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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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
    Microsoft Employee on at
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 125

#2
ParthPatel249 Profile Picture

ParthPatel249 87

#3
11manish Profile Picture

11manish 85 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans