JavaScript: “Execution Context” provides Form Values on Web as well as UCI in Dynamics 365 v9.0

By | August 6, 2018

Introduction:

No doubt, Microsoft Dynamics 365 v9.0 surprised us with the UCI feature which provides a generic user interface to users, this is about UI but behind the scene for developers also Microsoft provided “Execution Context” object which is a collection of array.

Recently we have a business requirement to perform some action using Custom button on contact and Dynamics 365 environment was v9.0.

As we all know we can pass the Execution Context using “Primary Control” CRM Parameter to Script function which we are calling on Click of Custom Button.

Java Script Execution Context provides Form Values on Web as well as UCI in Dynamics 365

So I did the same and got the “executionContext” in script and get the form context.

Source code:

function onClick(primaryControl)
    //function to bluid URL and open new window
{
    var functionName = "onClick: ";
   var executionContext = primaryControl;
    try {
        //validate execution context
        if (isValid(executionContext)) {
var formContext = executionContext.getFormContext();
            //get values
            var firstname = isValid(formContext.getAttribute("firstname")) && isValid(formContext.getAttribute("firstname").getValue()) ? 
        }
    } catch (e) {
        throwError(functionName, e.message);
    }
}

 

It works on Classic Mode of Dynamics.

Now I tried same with UCI mode by clicking same button and received error that “executionContext.getFormContext is not a function”.

Refer the below screenshot:

Java Script Execution Context provides Form Values on Web as well as UCI in Dynamics 365

Now, I debug and surprised that we can get field values which are on form within an executionContext itself only.

By making following change in source code we used var executionContext = primaryControl; instead of var formContext = executionContext.getFormContext();. And I noticed that it works like charm in Classic as well as UCI mode of Dynamics 365 v9.0:

function onClick(primaryControl)
    //function to bluid URL and open new window
{
    var functionName = "onClick: ";
   var executionContext = primaryControl;
    try {
        //validate execution context
        if (isValid(executionContext)) {
            //get values
            var firstname = isValid(executionContext.getAttribute("firstname")) && isValid(executionContext.getAttribute("firstname").getValue()) ? 
        }

    } catch (e) {
        throwError(functionName, e.message);
    }
}

For reference below are the properties we get when we pass “Primary Control” parementer,

Web:

Java Script Execution Context provides Form Values on Web as well as UCI in Dynamics 365

UCI:

Java Script Execution Context provides Form Values on Web as well as UCI in Dynamics 365

Conclusion:

We can get the form field values properties using executionContext itself in Dynamics 365.

Generate Your Own New Leads Now Within Dynamics 365 CRM with Maplytics

One thought on “JavaScript: “Execution Context” provides Form Values on Web as well as UCI in Dynamics 365 v9.0

  1. Shidin

    Thanks for this post.
    Confirms that I was not the only one who found this strange (at first) and then really useful.
    Only downside is I have to update the script files to make them UCI compliant.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *