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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Open ''close as won'' dialog on Opportunity with Javascript

(0) ShareShare
ReportReport
Posted on by 45

Hi Dynamics 365 community,

I have a problem that I think has a relatively easy solution to it, but I can't find it myself.

In our Business process flow we have a phase, let's call it phase 3. As soon as you leave this phase and go to phase 4, you have completed the opportunity phase and are moving to a new entity. We would therefore like to see the opportunity be closed as won when this transition takes place. The fields in the 'closed as won' dialog may be filled in manually. To ensure that people actually do this, we want to have the 'closed as won' dialog open as a pop-up as soon as you move from one phase(3) to the other(4). If this is not possible, we want to activate the dialog as soon as a field in phase 3 is changed. Does anyone know if this can be achieved on the page with javascript and what the javscript code should look like?

Thanks in advance for any tips.

Greetings.

Daimy

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at
    RE: Open ''close as won'' dialog on Opportunity with Javascript

    Hi Daimy,

    To load a Close as Won dialogue you can use following code:

    Mscrm.OpportunityCommandActions.opportunityClose(1);

    1.If you just want to open 'close as won'' dialog when one field has changed, All code you need is the code mentioned above.

    (1) Js code

    function openDialog() {
        Mscrm.OpportunityCommandActions.opportunityClose(1);
    }
    
    

    (2) Add the code to the field you need on Change event.

    For example, I select customer need field, when it’s value has changed, the dialog will open.

    pastedimage1604994722010v1.png

    pastedimage1604994728400v2.png

    2.If you want to open 'close as won'' dialog when move stage3 to stage 4 in bpf, you can refer following steps:

    (1) Js code:

    function formonload()
    {
    Xrm.Page.data.process.addOnStageChange(getStage); // Trigger the function when move to next stage.
    getStage();
    }
    
    function getStage()
    {
    var activeStage = Xrm.Page.data.process.getActiveStage();
    var stageId = activeStage.getId();
    var stagename = activeStage.getName();
    if (stagename == "Close") //stage4 name
    {
        Mscrm.OpportunityCommandActions.opportunityClose(1);
    }
    }

    (2) Add js to OnLoad event.

    pastedimage1604994890252v3.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Daimy Tamis Profile Picture
    45 on at
    RE: Open ''close as won'' dialog on Opportunity with Javascript

    Hi Leah Ju,

    Thank you for your detailed explanation. I have tried both methods. Method 2 works, but only if I go back from phase 4 to phase 3. Then the dialog appears. That will never happen, we won't go back in a phase. Method 1 seems more convenient to use. But if I copy and paste your code then I get an error when I change the field. error: ReferenceError: Web resource method does not exist:

  • Daimy Tamis Profile Picture
    45 on at
    RE: Open ''close as won'' dialog on Opportunity with Javascript

    Sorry, I made a typo in function. It works perfectly like this. Thank you so much!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 117 Super User 2025 Season 2

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 110

#3
#ManoVerse Profile Picture

#ManoVerse 56

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans