Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, June 8, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix .NET Extensions
Forum to discuss the use of .NET Extensions in SalesLogix version 7 and higher. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix .NET Extensions | New ThreadView:  Search:  
 Author  Thread: Capturing SLX Events in .NET
Matt Tollestrup
Posts: 7
 
Capturing SLX Events in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 29 Oct 08 12:50 PM
I am working on a .NET Extension, and I am wondering if it is possible to call a method within the .NET Extension when the AXFormChange event is raised in SLX. The COM interop example for using .NET highlights the ability to not re-create the .NET object every time it is needed, but instead just change the relevant variable(s) and re-use the object. This is attractive, but I haven't seen anywhere that allows for a Managed .NET Extension to be used like this unless it is through COM. I'd like to avoid having to register the DLLs if possible, so does anyone know if there is a way to accomplish controlling a .NET Extension once it has already been created without resorting to COM?

Thanks!
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Capturing SLX Events in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Oct 08 12:19 AM
There are a few ways to do this. One thing to keep in mind, you can call Application.Managed.Run as many times as you need. The way I do it is call Application.Managed.Create once to load/initialize the extension, then call Application.Managed.Run each time the form's Change event is fired, each time passing in the new ID. If other events are needed, you can pass those in as well to let the extension know how it should respond.

Does that make sense?
[Reply][Quote]
Seth Griner
Posts: 2
 
Re: Capturing SLX Events in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Oct 08 8:59 AM
There is no way to avoid COM, but the good news is, you can avoid all of the registration by creating your .NET class the right way. An example .NET class is something like:

using System;
using System.Runtime.InteropServices;
using Sage.SalesLogix.NetExtensions;

namespace Sincera.Slx.NetExtensions
{
[ComVisible(true)]
[Guid("F97D36EF-D10A-48bf-A58C-690201D315D4")]
public class ExampleExtension : BaseRunnable
{
public override object Run(object[] args)
{
return this;
}

public void DoSomething(string val)
{
System.Windows.Forms.MessageBox.Show(val);
}

public int Add(int num1, int num2)
{
return num1 + num2;
}
}
}

They keys to the above are adding the ComVisible attribute and returning the current object in the Run method. I've also added a Guid attribute above, which isn't really necessary, but it is a good habit to get into when playing around with COM. You should generate a new unique Guid for each COM class you create.

When I create a .NET extension like above, I generally create a corresponding VBScript class in SalesLogix:

Class ExampleExtension
Private guid_, obj_

Private Sub Class_Initialize()
guid_ = Application.Managed.Create("Sincera.Slx.NetExtensions", "Sincera.Slx.NetExtensions.ExampleExtension")
Set obj_ = Application.Managed.Run(guid_, Empty)
End Sub

Private Sub Class_Terminate()
Set obj_ = Nothing
Application.Managed.Destroy guid_
End Sub

Public Sub DoSomething(val)
obj_.DoSomething val
End Sub

Public Function Add(num1, num2)
Add = obj_.Add(num1, num2)
End Function
End Class

In the Class_Initialize method, I'm creating the extension and calling Run, which gives me back the instance of the .NET class, which I store so I can use it later. In the Class_Terminate method, I'm just making sure to release my resources. The other two methods are just direct wrappers around the methods of the .NET class.

I can use this class in SalesLogix like this:

Dim ext
Set ext = New ExampleExtension
ext.DoSomething "This is a test."
MsgBox ext.Add(10, 20)
Set ext = Nothing

In your case, you could create the extension object in the AXFormCreate event, clear it out in the AXFormDestroy method, and call any of it's methods in AXFormChange or where ever else you need.

Dim ext
Sub AXFormCreate(sender)
Set ext = New ExampleExtension
End Sub

Sub AXFormDestroy(sender)
Set ext = Nothing
End Sub

Sub AXFormChange(sender)
ext.DoSomething("The form has changed.")
End Sub
[Reply][Quote]
Matt Tollestrup
Posts: 7
 
Re: Capturing SLX Events in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Oct 08 9:58 AM
It does make sense, but I must not understand enough about how to do that. I tried testing some code like that, adapting your example of the COM model of putting the application into the GlobalInfo cache and then pulling it back out, but I can't seem to get the Run to fire again on the second attempt. When passing Args, I would need to build an Object Array because I pass in the HWND to resize the UserControl and set its parent, and additionally I want to pass in a few other parameters that would allow me to basically use a Switch and execute different code commands based on additional variables submitted.

I have been playing with this code, but I'm not understanding something about SLX and/or .Net Extensions because something is just not firing quite right. Any pointers would be greatly appreciated!

Sub AXFormChange(Sender)

Dim Loader
Dim Args(3)

Args(0) = Form.HWND

if Application.GlobalInfo.IndexOf("PRISLX") = -1 Then
Loader = Application.Managed.Create("SLXNetExtensionSandbox", "SLXNetExtensionSandbox.UserControl1")
Application.Managed.Run Loader, Args
Application.GlobalInfo.Add "PRISLX", Loader
Else
Loader = Application.GlobalInfo.IndexOf("PRISLX")
Args(1) = 1
Args(2) = "Hello Once Again from SLX"
Application.Managed.Run Loader, Args
End If

End Sub
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Capturing SLX Events in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 31 Oct 08 10:38 AM
Matt, you are setting the loader variable to te index of PRISLX and not the value of the global

Mark
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Capturing SLX Events in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Nov 08 3:25 PM
Ryan,

Your last statement: "If other events are needed, you can pass those in as well..." Did you mean arguments? If you did mean events, how exactly would pass them in?

Thx,

Jeff
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Capturing SLX Events in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Nov 08 3:44 PM
There are two options. The one I was referring to is listed as #1 below:

1) Simply pass in a string name of the event that is firing in SLX. You create the event handler in the script and then pass in the event name like "ButtonClick" so in the extensions Run method you can identify how to respond. This is a simple and easy way to accomplish this.

2) Expose the object so you can use GetRef in VBScript to get a pointer to it and then call it as needed. This way works, but I think that option 1 is much simpler and accomplishes the same.

-Ryan
[Reply][Quote]
Kevin Hoelzel
Posts: 6
 
Re: Capturing SLX Events in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Feb 09 2:39 PM
I'm actually in the middle of updating one of my own posts about this. Jeff Ballard and I were able to work out a lot of details regarding calling .NET methods from SalesLogix Active Script. I'd be willing to collaborate on an article with you if you like and I know Jeff would as well as we've already discussed this.

The best way we found to accomplish calling .NET methods from Active Script was to created the managed application in SalesLogix as an object. Then you can add the object.dotnetmethod() line of code to events in Active Script. This is predicated on the fact you set the attribute in the .NET code [Com Visible(true)]. This did not require making the assembly Com Visible and did not require a ProgId. In fact, in the Extension Manager, the Com Visible still shows False but it still works.

As you can see below, the managed application is created and when run is called, we create an object from that which we can now access from all events on the detail form. I've included the short version of the Validate function to demonstrate how we called the .NET SaveOpportunity() method from the forms Validate event.

Code Sample from Opportunity Detail:

option explicit

Dim managedClass
Dim args(3)
Dim isValid
Dim dotNetObj

Sub AXFormChange(Sender)
args(0) = frmOpportunityDetail.HWND
args(1) = frmOpportunityDetail.CurrentID
args(2) = ""
args(3) = false

If Application.GlobalInfo.IndexOf("opportunityExtension") <> -1 Then
managedClass = Application.GlobalInfo.Item("opportunityExtension")
Else
managedClass = Application.Managed.Create("Opportunity Main View", "Lumension.SalesLogix.NetExtension.OpportunityDetail")
Application.GlobalInfo.Add "opportunityExtension", managedClass
End If

Set dotNetObj = Application.Managed.Run(managedClass, args)

End Sub
Function AXFormValidate(Sender)
dotNetObj.SaveOpportunity()
End Function
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 6/8/2025 2:12:44 PM