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