Interacting Table Level Scripts: A Chain Reaction

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Interacting Table Level Scripts: A Chain Reaction

  • Comments 1
  • Likes

Consider this scenario.

There is an UpdateRecord() event function in a TLS on the Company.  When the Company assigned user is changed (comp_primaryuserid) then all the 'In Progress' opportunities belonging to that company are reassigned to the new company account manager (oppo_assigneduserid).

You can see how that can be done in the article "A Table Level Script to update Opportunities when a Company is Reassigned".

But what happens if there is a Table Level script on Opportunities that has an UpdateRecord event function?  This event function could be triggered either by a user making a direct change to an opportunity through the interface or an indirect change that is made by another Table Level Script.  

How does the triggering differ?  What implication will that have on the design of the Table Level Script?

Consider the following UpdateRecord event function


function UpdateRecord()
{
Valid = false;
ErrorStr = "Values('oppo_assigneduserid'): " +Values("oppo_assigneduserid"); 
ErrorStr += "<BR> GetContextInfo('opportunity','oppo_assigneduserid'): "+CRM.GetContextInfo("opportunity","oppo_assigneduserid");
ErrorStr += "<BR> WhereClause used: "+ WhereClause;
}
 

When the UpdateRecord event is triggered by a direct change to the Opportunity then the data it returns will look like:

 

  • Values('oppo_assigneduserid'): 4
  • GetContextInfo('opportunity','oppo_assigneduserid'): 5
  • WhereClause used: Oppo_OpportunityID = 3

We can see the WhereClause variable returns the ID of the opportunity that is being directly changed.

The Values() collection returns the value of the new oppo_assigneduserid, and the GetContextInfo will return the value in the database.

When the UpdateRecord event is triggered by a change to the Opportunity driven by another Table Level Script (e.g. A Table Level Script to update Opportunities when a Company is Reassigned.) then the WhereClause passed to the Opportunity TLS is different.   

  • Values('oppo_assigneduserid'): 4
  • GetContextInfo('opportunity','oppo_assigneduserid'): 4
  • WhereClause used: oppo_status = 'In Progress' and oppo_primarycompanyid=41 AND oppo_Deleted is null

Note:

In both cases only a single UpdateRecord event function on the Opportunity has fired.

This means when designing the Oppo TLS you would have to take into account the possibility of it triggering a batch affecting a set of records and not just a single record.

Also you may note a discrepency in the the value returned by the GetContextInfo('opportunity','oppo_assigneduserid').  This is because although the preceding Company Table Level Script changes the value of the oppo_assigneduserid these changes have not yet been committed into the database when the 'chained' Opportunity Table Level Script is triggered. 

Comments
  • Hello,

    I don't understand this afirmation: "This is because although the preceding Company Table Level Script changes the value of the oppo_assigneduserid these changes have not yet been committed into the database when the 'chained' Opportunity Table Level Script is triggered. "

    i think that If this is correct, the result would be Values('oppo_assigneduserid'): 5

    GetContextInfo('opportunity','oppo_assigneduserid'): 5

    Because 4 is the new value.