web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how to send execution context to the below function

(0) ShareShare
ReportReport
Posted on by 244

I need to send formcontext to myFunction. The below line is called on OnLoad method.

formContext.data.process.addOnStageChange(myFunction);

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hello there!

    The execution context is automatically passed as the first parameter to the function, So you dont need to worry about that. Are you getting any error?

    have a look : docs.microsoft.com/.../addonstagechange

  • gdas Profile Picture
    50,091 Moderator on at

    Try with this  -

    //Register below function in Onload and pass execution context from event handler
    
    function Onload(executionContext) {
        var formContext = executionContext.getFormContext();
        formContext.data.process.addOnStageChange(myFunction);
    }


  • NK Bhairi Profile Picture
    244 on at

    i am asking on how to pass executionContext to myFunction().

    Assuming myfuction has the capbility to take formcontext as first param.

    I have tried the following.

    function myFunction(formcontext)

    {

    formcontext.ui.process.setDisplayState("collapsed");   --->this is where i m getting error process is undefined

    }

  • Rawish Kumar Profile Picture
    13,758 on at

    can you please post the full code.

    you are passing the formContext - but code woundnt know from where formContext is coming.

    rather you pass executionContext in the function and then do something like executionContext.getFormContext()

    Refer to Goutam's code above.

  • gdas Profile Picture
    50,091 Moderator on at

    This line is missing in your code-

    var formContext = executionContext.getFormContext();

    See my code posted above.

  • Community Member Profile Picture
    on at

    Hello miss,

    Kindly note the highlighted check box

    EnableExecutionContext.PNG4426.EnableExecutionContext.PNG

  • NK Bhairi Profile Picture
    244 on at

    function onload(executionContext)--->called this on form onLoad and is enabled and passed execContext first param

    {

    var formContext=executionContext.getFormContext();

    formContext.data.process.addOnStageChange(myFunction);

    }

    function myFunction()

    {

    Xrm.Page.ui.process.setDisplayState("collapsed");// I want to change this to formContext.process but for that i need to pass either execution context or formcontext to myFunction  

    }

  • Suggested answer
    Community Member Profile Picture
    on at

    function onload(executionContext)--->called this on form onLoad and is enabled and passed execContext first param

    {

    var formContext=executionContext.getFormContext();

    formContext.data.process.addOnStageChange(myFunction(formContext));

    }

    function myFunction(formContext)          // Pass it as a parameter

    {

    Xrm.Page.ui.process.setDisplayState("collapsed");// I want to change this to formContext.process but for that i need to pass either execution context or formcontext to myFunction  

    formContext.process.setDisplayState("collapsed");

    }

  • Verified answer
    Daniel Wikell Profile Picture
    2,360 on at

    Hi Miss Dynamics

    When you want to pass parameters to a function that is used as a parameter in another function call you can utilize the Anonymous function declaration and call myFunction like this:

    var formContext = executionContext.getFormContext();
    
    formContext.data.process.addOnStageChange(function() {
       myFunction(formContext);
    
    });


    The anonymous function is sent as the parameter for addOnStageChange and inside it you have the option of doing whatever you want which in this case means calling your own function with parameters.

  • CrmLeo Profile Picture
    35 on at

    Well understood the issue and great answer. Thanks Daniel Wikell for the answer and Miss Dynamics for the question.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans