Skip to main content

Notifications

Announcements

No record found.

Sales forum
Answered

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

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

  • Daimy Tamis Profile Picture
    Daimy Tamis 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!

  • Daimy Tamis Profile Picture
    Daimy Tamis 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:

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

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

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,349 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,212 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans