Use execution context and the form event pipeline
Applies To: Dynamics CRM 2013
This topic describes how to use the Form event pipeline to manage multiple event handlers for an event, and how to use execution context to re-use JavaScript library functions for different events.
Execution context
When you associate a function in a JavaScript library to an event handler in Microsoft Dynamics CRM, you can check the Pass execution context as first parameter option. The following table lists the execution context object methods.
Method |
Description |
---|---|
Returns the Xrm.Page.context object. See Client-side context (client-side reference) for more information. |
|
Returns a value indicating the order in which this handler is executed. |
|
Returns a reference to the object that the event occurred on. |
|
Retrieves a variable set using 279ca720-e304-4e51-b99f-91722431c2c8#BKMK_SetSharedVariable. |
|
279ca720-e304-4e51-b99f-91722431c2c8#BKMK_SetSharedVariable |
Sets the value of a variable that can be used by a hander after the current handler finishes. |
Use the getEventSource method in functions to make them more generic. For example, if you have a function that formats a telephone number, you can use the getEventSource method to refer to whatever attribute caused the onChange event. Your functions do not need to reference a specific attribute.
Form event pipeline
You can define up to 50 handlers for each event. Each handler is executed in the order that it is displayed on the Events tab of the form element properties dialog box. This corresponds to the list of <Handler> (FormXml) elements in the <Handlers> (FormXml) element for an event.
Use the 279ca720-e304-4e51-b99f-91722431c2c8#BKMK_SetSharedVariable and getSharedVariable methods to pass a common variable between functions. Use the execution context getDepth method to know the sequence that a function is being executed in relative to other handlers.
See Also
Write code for Microsoft Dynamics CRM 2013 forms
Use form and field events
Use the Xrm.Page object model
Use an IFRAME and web resource controls on a form
Use JavaScript with Microsoft Dynamics CRM 2013