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.
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:
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:
UCI:
Conclusion:
We can get the form field values properties using executionContext itself in Dynamics 365.