Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Trigger JavaScript when Opportunity is Closed

(1) ShareShare
ReportReport
Posted on by 7
Hello,
 
I want to show a section in the Opportunity form using JavaScript as soon as the opportunity is Closed. However, I'm unable to find an event that would trigger once Opportunity is Closed.
 
As per the following community discussion, it seems like the only way available is to use Ribbon Workbench to trigger JavaScript on the Click of Close as Won or Close as Lost buttons. But clicking on these buttons and opening the Opportunity Close dialog doesn't mean the opportunity is closed, the user could choose to close the dialog and not close the opportunity.
 
Is there any way to achieve this? Thanks in advance for the help.
 
  • Verified answer
    Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Trigger JavaScript when Opportunity is Closed
    Hi,
     
    You can register an onchange event on the Status field.
    When the status field value changes to 1 or 2 (indicating that the opportunity is closed), perform a custom action.
     
    The demo code is shown below;
     
    function onchange(executionContext){
        var formContext = executionContext.getFormContext();
        var statuscode = formContext.getAttribute("statecode").getValue();
     
        if(statuscode ==1||statuscode==2){
            //Do something here
            console.log("Opportunity is closed!");
        }
    }
     
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li
     

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans