Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Business Process Flow - Move Next

Posted on by Microsoft Employee

Hello,

I'm here regarding a Question for the new Clientside Methods for Business Process Flows. 

I'm trying to set the Stage of a Business Process Flow. On my Entity there is an Optionset that gets the State from a System outside of CRM and i want to set the Stage of the Business Process flow. Now im trying to get the Value of the Optionset and look if the BPF is on that state. If not, the BPF will be set back to the first Step. Then i Iterate through it with a foreach and check everytime if the names are the same. Here is the problem. Move next only triggers on the first time not on the following.

function SetStageForCustomerQualification() {
    var customerQualification = Xrm.Page.getAttribute("accountcategorycode").getSelectedOption();
    var currentProcess = Xrm.Page.data.process.getActiveProcess();
    var stageCollection = currentProcess.getStages();
    var alreadySet = false
    stageCollection.forEach(function(stageObj, n){
        var tempStageId = stageObj.getId();
        var tempStageName = stageObj.getName(); 
        if(n == 0){
            var tempStageId = stageObj.getId();
            console.log(n);
            Xrm.Page.data.process.setActiveStage(tempStageId);
            Xrm.Page.data.entity.save();
        }
        if(tempStageName == customerQualification.text){
            alreadySet = true;
            console.log("Set currentstage: " + alreadySet);
            Xrm.Page.data.process.setActiveStage(tempStageId);
            Xrm.Page.data.entity.save();
        }else if(alreadySet == false){
            console.log("Movenext: " + alreadySet);
            Xrm.Page.data.process.moveNext();
            Xrm.Page.data.process.setActiveStage(tempStageId);
            Xrm.Page.data.entity.save();
        }  
    });
}

Hoping for answers 

BR Lucas

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Business Process Flow - Move Next

    Hi Lucas,

     did you try to debug the script? When you are saying that "moveNext only triggers the first time", do you mean that the script just stops after that? According to the "if" conditions there, if the script continues, it will not trigger "moveNext" only if alreadySet becomes true.. is it possible you've reached the right stage?

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans