Open Close as Won dialogue with JavaScript on Opportunity

You might come across a requirement where you wan to open Close as Won or Close as Lost dialogue when user gets to last stage of business process flow on Opportunity form.

Out of the box button (‘Close as Won’) calls a JavaScript command to load this dialogue and we can call same command to load Close as Won dialouge

Following command is to trigger a JavaScript function on stage change of business process flow;

You can check stage by calling following code

status =;

if (status == "finished")


To load a Close as Won dialogue you can use following code


To load Close as Lost you can use following code


I have used this in D365 and it works perfectly.

You might not need to loas this on finish stage of business process flow but you can call above code anywhere you need.

Below is the full code

function OnLoad() {;

function statusOnChange() {
status =;
if (status == “finished”) {

Hope this helps.

Comments are closed.