Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

confirm dialog in business process flow

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

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans