Tuesday, August 6, 2024

Trigger JavaScript on Business Process Flow Buttons in MSCRM or Dataverse

 ​Implementation Steps:

 
 
2. Click On Solutions
 
3. Create a New Solution
 
4. Create a New JavaScript (in my case its Opportunity.js)

 















5. Copy Paste the Below Code for your JavaScript
 
function onLoad(e) {
    var bpf = e.getFormContext();
    bpf.data.process.addOnPreStageChange(handlePreStage);
};

function handlePreStage(e) {
    var bpf = e.getEventArgs(), entityName = Xrm.Page.data.entity.getEntityName()

    if (bpf.getDirection() === "Previous") {

        bpf.preventDefault();

        var alertStrings = { confirmButtonLabel: "OK", text: "You have Clicked Previous button"};
        var alertOptions = { height: 150, width: 260 };

        Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);

        return;
    }
    if (bpf.getDirection() === "Next") {

        bpf.preventDefault();

        var alertStrings = { confirmButtonLabel: "OK", text: "You have Clicked Next button"};

        var alertOptions = { height: 150, width: 260 };

        Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);

        return;

    }
}

 
6. Now Open Opportunity Table --> Opportunity Form and add an ONLOAD EVENT
 













 
7. Once Done --> Save and Publish
 
 
8. Now Open Opportunity Table --> Open a Record
 
9. Click Business Process Flow --> Click Next
 


 
 








10. Again Click on Business Process Flow --> Click Back Button
 


 
 








That's it :)
 

1 comment:

  1. What about when an action step is selected within a stage?

    ReplyDelete

How to Clear Cache in Canvas PowerApps while working on Offline mode?

  Introduction In this blog, we’ll look at how to clear cache in Canvas Apps when using the Power Apps mobile application, especially when t...