Hi,
In a customized business process flow (on a single entity) I want the user to confirm when moving backwards in the BPF. It's a reminder that he/she has to redo a lott of stuff before progressing again.
I would like you use the new API onPreStageChange but haven't got it working in JavaScript. I followed Richards' example linked below. The big change is that I don't want to abort the execution and notify the user, I want the execution to wait untill the users decides.
The code basically looks like this:
The first function is called onLoad of the form
function registerOnStageChangeEvents(executionContext) { formContext.data.process.addOnPreStageChange(myPreStageChangeChecks); formContext.data.process.addOnStageChange(throwalertfunction); } function myPreStageChangeChecks(executionContext) { console.log("I started a state change!"); var formContext = executionContext.getFormContext(); var process = formContext.data.process; var eventArgs = executionContext.getEventArgs(); var currentStageId = process.getActiveStage().getId(); var nextStageId = process.getSelectedStage().getId(); var sourceId = executionContext.getEventSource(); var confirmStrings = { cancelButtonLabel: "Cancel", confirmButtonLabel: "Continue", subtitle: "Are you sure?", title: "Confirm leaving stage", text: "Choices have consequences" }; var confirmOptions = { height: 150, width: 260 }; if ((currentStageId != nextStageId) || eventArgs._direction === 1){ eventArgs.preventDefault(); // block everything Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(function(success){ if(success.confirmed){ console.log("go on..."); formContext.data.process.movePrevious(); // try to start again } else { console.log("aborting"); } }, function(error){ console.log(error); }); return; } }
The problem is that by blocking all events (eventArgs.preventDefault();), I need to start the stage change again, but that call (formContext.data.process.movePrevious();) will trigger the onPreStageChange() again, building a loop.
If I don't stop the execution, the dialog is opened, but in the background the stage change continious.
How can I fix this? How do I 'insert' a asynchronous action (like waiting for user input) in the onPreStageChange?
Many thanks!
Resources used:
https://www.richardawilson.com/2019/10/dynamics-bpf-javascript-new.html
Hello Jeroen,
Did you manage to cover this requirement in a supported way?
If not, have you considered suggesting new supported methods in Power Apps: https://aka.ms/PAIdeas
Henry
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,151 Super User 2024 Season 2
Martin Dráb 229,993 Most Valuable Professional
nmaenpaa 101,156