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.
 
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 189 Super User 2026 Season 1

#2
CU11031447-0 Profile Picture

CU11031447-0 100

#3
NeerajPawar Profile Picture

NeerajPawar 66

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans