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

Announcements

No record found.

News and Announcements icon
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

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans