Hi,,
Can anyone explain the use of passing execution context as parameter into function by an example.
Hi,,
Can anyone explain the use of passing execution context as parameter into function by an example.
Hi partner,
All that said above is right.
What I want to add is that "execution context" can also used to do some saving actions.
For example,you want to prevent saving form if some conditions are not met, you could use the following code.
function validateEmail(executionContext){
executionContext.getEventArgs().preventDefault();//prevent updating the record
}
}
And we should select "Pass execution context as first parameter" when trigger this action.
Hope it helps.
Best Regards
Leo
Hi,
This is used to get the form context to your JavaScript method which will then be used to retrieved the form fields etc. For example, if you want to get the name of account in JS, you need to get it from the form context which will be retrieved from the execution context. This was there for very long (I guess since 2011) but with the release of D365 V9, it is now the recommended/ supported way to work with form field.
Basically, before V9, we used to get the field value like this Xrm.Page.getAttribute("name").getValue, however Xrm.Page is now deprecated. So now, we need to pass the execution context from the event properties and use it in our method. This execution context is also used to return the gridcontext if you want to write any script on subgrids etc
==================================
// Get account name in v8.2 & below
function getAccountName()
{
var accountName = Xrm.Page.getAttribute("name").getValue();
console.log("Account Name is: "+ accountName);
}
// Get account name in v9.0 & above
function getAccountName(executionContext) {
var formContext = executionContext.getFormContext(); // get formContext
var accountName = formContext.getAttribute("name").getValue(); // use formContext instead of Xrm.Page
console.log("Account Name is: " + accountName);
}
==================================
Refer these links for more detail-
https://sachinbansal.blog/2018/04/27/all-javascript-changes-dynamics-365-9-0/
https://develop1.net/public/post/2017/11/11/executionContext-hits-the-big-time!
This is the official documentation for execution context: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/execution-context
Hope this helps.
Hi Priyanka ,
I have updated my answers as thought you asked about parameters .
For Execution context I believe below article will clear your doubt -
https://community.dynamics.com/crm/b/develop1/archive/2017/11/11/executioncontext-hits-the-big-time
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156