web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

confirm dialog in business process flow

(0) ShareShare
ReportReport
Posted on by 15

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

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/events/onprestagechange

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openconfirmdialog

I have the same question (0)
  • Suggested answer
    Henry J. Profile Picture
    5,237 on at
    RE: confirm dialog in business process flow

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
#ManoVerse Profile Picture

#ManoVerse 101

#2
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 66 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans