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

Notifications

Announcements

No record found.

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.
 
I have the same question (0)
  • 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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 185 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 110

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans