Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Unanswered

Facing an issue while saving BPF explicitly through JS.

Posted on by 5

Hi, I am facing an issue on the change stage of BPF.

My scenario is: I'm making an approval process using BPF. So I want to move stages and update BPF accordingly. So for instance, there are 2 Persons involved in the approval process. Person A and B. Now if A approves (approval is an option set) then the stage moves to the next stage and Person B is now responsible for the approval. Now if person B rejects, then the stage would reset to the starting stage i.e. person A's stage. Now the problem is, we are setting the active stage after checking if the person B's approval optionset is set to rejected, and then saving the form explicitly. So what it does now is we have to click 2 times in order to make the expected change. We are doing this in JS and using addOnPreStageChange() and we are preventing the default behavior which moves it to next stage. Kindly refer to the code and screenshots below for better understanding.

Code:

function HideStageButton(executionContext){
    var formContext = executionContext.getFormContext();
    formContext.data.process.addOnPreStageChange(StageChange);
}

 

function StageChange(executionContext){
    var direction = executionContext.getEventArgs().getDirection();
if(direction=="Next"){

///--->For Rejected Stage----------->

    if(executionContext.getFormContext().getAttribute("np_programheadapproval").getValue()==2){
        executionContext.getEventArgs().preventDefault();
        Xrm.Page.data.process.setActiveStage("10ae7c3e-4613-4b30-be9b-894c82c8c0e9", ()=>{console.log("Hello world")});
        executionContext.getFormContext().data.entity.save();
        executionContext.getFormContext().getAttribute("np_programheadapproval").setValue(null);
    
    }
}
For Person A
pastedimage1655453648606v2.png
For Person B
pastedimage1655453704421v3.png

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans