Community
Showing results for 
Search instead for 
Do you mean 
Reply

Creating Triggers From SDK

Copper Contributor
Posts: 61
Country: United_Kingdom

Creating Triggers From SDK

Hi Guys,

 

Just wanted to check my managers have requested me to create some triggers based upon some opportunities and company fields? Is this possible or is there any way around with the SDK so that I will create some messages or some fields on opportunities and company views.

 

Thanks

Employee
Posts: 1,163
Country: USA

Re: Creating Triggers From SDK

Yes, there are already some events that exist in the API, such as and most relevant to your needs, FieldChanged

 

ActApp.ApplicationState.CurrentCompany.Fields.FieldChanged += new MutableEntity.FieldCollection.FieldChangedHandler(Fields_FieldChanged);

 

void Fields_FieldChanged(string fieldName)
{
//DoStuff
}

 

From there you'll have the name of the field that has changed so you can capture the FieldDescriptor and make modifications or display messages as needed.

Matthew Wood
Act! SDK Support
Community Moderator
Copper Contributor
Posts: 61
Country: United_Kingdom

Re: Creating Triggers From SDK

Thanks Matthew I will give it a try.

Copper Contributor
Posts: 61
Country: United_Kingdom

Re: Creating Triggers From SDK

Hi Matthew, could you please convert this to VB.Net I have tried every possible way but couldn't find the correct correspondence in VB. Thanks

 

 

Nickel Contributor
Posts: 175
Country: USA

Re: Creating Triggers From SDK

http://www.developerfusion.com/tools/convert/csharp-to-vb/

 

This is probably the "defacto-standard" converter tool around. It's not 100% correct (pretty darn close though), but I don't recall ever having an issue directly using the converted code. If you want 100%, you'll need to use the "Roslyn" project/code from Microsoft, which deals with the compilers (more difficult than just copy & paste a few times).

Copper Contributor
Posts: 61
Country: United_Kingdom

Re: Creating Triggers From SDK

Hi Matthew I was wondering whether if I can put a trigger for all opportunities ? Like when a field is changed in company all opportunities which are going to be created under this company will get a default selection or a warning ?

Employee
Posts: 1,163
Country: USA

Re: Creating Triggers From SDK

Regardless of which company record you're on, the FieldChange event will fire when changes are made to the field in question. The company class also has a GetOpportunities method so when the event fires, you can get all associated opportunities and do with them whatever you like, so from above:

 

void Fields_FieldChanged(string fieldName)
{
    OpportunityList oppList = myCompany.GetOpportunities(null)

    //DoStuff
}

 

 

Matthew Wood
Act! SDK Support
Community Moderator
Copper Contributor
Posts: 61
Country: United_Kingdom

Re: Creating Triggers From SDK

Hi Matthew I did come this far but now I'm having problem accessing the opportunites fields since when I get them from myCompany.GetOpportunities(null) I cannot access to FieldDescriptors method, is there any way around this?

 

Thanks

Employee
Posts: 1,163
Country: USA

Re: Creating Triggers From SDK

GetOpportunities does not return field descriptors, it returns Opportunities associated with the given company. 

 

You can create an instantiate an Opportunity FieldDescriptor like so:

 

DBFieldDescriptor dbf = ActApplication.ActFramework.Opportunities.GetFieldDescriptor("TBL_OPPORTUNITY.USER1");

 

From there you can get and set the value of the field as you wish. 

Matthew Wood
Act! SDK Support
Community Moderator
Copper Contributor
Posts: 61
Country: United_Kingdom

Re: Creating Triggers From SDK

Hi Matthew as usual my C# program doesn't works in ACT so I'm back in VB again now I have everything but I'm stuck in creating the handler for field changed event when I create the handler like this

 

AddHandler HostApplication.ApplicationState.CurrentCompany.Fields.FieldChangedHandler, AddressOf New MutableEntity.FieldCollection.FieldChangedHandler(Field_Changed)

 

which is almost the same as C# I get an error "

Error 5 Delegate 'Act.Framework.MutableEntities.MutableEntity.FieldCollection.FieldChangedHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor. " like this am I missing something ?

 

Thanks