Client API execution context

We can pass the execution context in the following way.

Defining event handlers using UI: The execution context is an optional parameter that can be passed to a JavaScript library function through an event handler. Use the Pass execution context as first parameter option in the Handler Properties dialog while specify the name of the function to pass the event execution context. The execution context is the first parameter passed to a function.




The Client API form context (formContext) provides a reference to the form or to an item on the form, such as, a quick view control or a row in an editable grid, against which the current code is executed.
Earlier, the global Xrm.Page object was used to represent a form or an item on the form. With Dynamics 365 (online), version 9.0, the Xrm.Page object is deprecated, and for you should use the getFormContext method of the passed in execution context object to return reference to the appropriate form or an item on the form.

Utilizing the formContext object rather than the Xrm.Page object

Please find the below sample code for example

Using Xrm.object
Function contactDetails()
{
         var fName = Xrm.Page.getAttribute("firstname").getValue();
    var lName = Xrm.Page.getAttribute("lastname").getValue();
}

Using formContext
function contactDetails(executionContext)
{
    var formContext = executionContext.getFormContext(); //to get the formContext

    // use formContext instead of Xrm.Page 
    var fName = formContext.getAttribute("firstname").getValue();
    var lName = formContext.getAttribute("lastname").getValue();
   
}

Comments

Popular posts from this blog

Workflow Activity Input and Output Parameters and Data Types in MS CRM 2013/15/16

Get Workflow Guid in Javascript using OData query

Convert Plugin to Sandbox mode,