0

I have created a BPF in CRM 365. In that after selecting 1 value on first stage another stage gets opened and that will be last stage. As you can see in the screenshot, I need to call javascript function on click of "Finish" button. If I get that event, I would be checking the value of Create Follow up field. If that is No, then I will do some logic henceforth.

Now my question is : How to get that Finish button event in that stage so that it goes to javascript code?

Any pointers please?

enter image description here

Prashant
  • 21
  • 7
  • Does this answer your question? [How to get Process Finish Button event in Dynamics CRM?](https://stackoverflow.com/questions/47950490/how-to-get-process-finish-button-event-in-dynamics-crm) – Arun Vinoth-Precog Tech - MVP Jul 22 '20 at 16:06
  • I already tried your answer before making this question. I have done the exact steps that you said but I was unable to get trigger event in that addOnProcessStatusChange. Upon checking F12 I saw that when I clicked Finish button, the debugger didn't went to that said function. – Prashant Jul 22 '20 at 16:57
  • Unfortunately we dont have direct event for Finish button. so better troubleshoot the code why its not working. – Arun Vinoth-Precog Tech - MVP Jul 22 '20 at 17:13
  • Anyone there how can help me out in this? – Prashant Jul 24 '20 at 13:55

1 Answers1

0

This is a working example of an entity form's JavaScript web resource,

var PUBLISHER = PUBLISHER || {};

PUBLISHER.pub_entityname = PUBLISHER.pub_entityname || (function () {

    return {

        onFormLoad: function (executionContext) {
            var formContext = executionContext.getFormContext();
            // Declare BPF OnProcessStatusChange event handler and pass in
            // your own function. Execution context is passed in automatically.
            formContext.data.process.addOnProcessStatusChange(BpfStatusChange);
        }

    };

    function BpfStatusChange(executionContext) {
        var formContext = executionContext.getFormContext();
        var bpfStatus = formContext.data.process.getStatus();

        if (bpfStatus === "finished") {
            // Do something.
        } else if (bpfStatus === "aborted") {
            // Do something.
        } else if (bpfStatus === "active") {
            // Do something.
        }
    }

})();

The 'OnProcessStatusChange' event handler needs to be created manually in the form's 'onLoad' event. There are three BPF statuses available, when a user clicks the 'Finish' or 'Next' button, this will react if the Business Process Flow's status changes.

MS Docs

mepilp
  • 97
  • 2
  • 12