Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

execution context

Posted on by 70

Hi,,

Can anyone explain the use of passing execution context as parameter into function by an example.

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: execution context

    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

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: execution context

    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!

    https://docs.microsoft.com/en-us/dynamics365/get-started/whats-new/customer-engagement/important-changes-coming#some-client-apis-are-deprecated

    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.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: execution context

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans