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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Business Process Flow - Move Next

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    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

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans