Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

JavaScript to confirm before BPF movement not working

$
0
0

Hi Experts,

Need help on below JavaScript, everything working fine except, when user selects the next stage, Confirm Dialog prompt for confirmation, but when user click on OK button in the dialog box, this action does not move to next stage. Simply its close the dialog box. if anyone can help me on this?

function onLoad(executionContext) {
    var formContext = executionContext.getFormContext();
    var process = formContext.data.process;        

    //handles changes to the BPF before they actually occur
    process.addOnPreStageChange(myProcessStateOnPreChange);
}

function myProcessStateOnPreChange(executionContext) {

    var formContext = executionContext.getFormContext();
    var process = formContext.data.process;
    var eventArgs = executionContext.getEventArgs();

    var currentStageId = process.getActiveStage().getId();
    var nextStageId = process.getSelectedStage().getId();

    //dont allow to go back using the set active button
    if (currentStageId != nextStageId) {
        eventArgs.preventDefault();
        Xrm.Utility.alertDialog("You cannot set completed stage as Active.")
        return;
    }        
         
    if (eventArgs._direction === 1) //backwards
    {            
        //logic based upon the BPF going to the previous Stage.
        eventArgs.preventDefault();
          var alertStrings = { cancelButtonLabel: "Cancel", confirmButtonLabel: "OK", text: "Backward stage movement is not allowed", title: "Warning" };
          var alertOptions = { height: 120, width: 260 };
          Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
        return;
    }

    //otherwise forward
    //logic based upon the BPF going to the next Stage.
    else
    {   eventArgs.preventDefault();
        var confirmStrings = {
            cancelButtonLabel: "Cancel",
            confirmButtonLabel: "OK",
            text: "Are you sure you want to move forward in the BPF?",
            title: "Confirm BPF Movement"
        };
        var confirmOptions = { height: 120, width: 260 };
        Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(function(success) {
            if (success.confirmed) {
                formContext.data.process.moveNext();
                console.log("BPF movement confirmed");
            } else
            {
                console.log("BPF movement cancelled");
            }
        });
    }
    //Xrm.Utility.alertDialog("Warning: You cannot undo this movement.")
  }
 

Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>