In this course, we will learn to move the business process flow to next stage using JavaScript. Before we start, make sure to go through the below courses.
- Understanding JavaScript in Dynamics CRM
- How to use JavaScript in Dynamics CRM?
- Using formContext in JavaScript
- Get & Set value in fields using JavaScript
- Hide / Show fields using JavaScript
- Hide / Show tabs using JavaScript
- Lock / Unlock fields using JavaScript
Moving the BPF to next stage
We will use the method “formContext.data.process.moveNext” client API for moving the Business Process Flow to the next stage. Consider the below Account record having business process flow called “Account BPF”.
Consider the below JavaScript code which is fired during OnSave event of the form record.
function BPFMove(executionContext) { //Initiated Form Context. var formContext = executionContext.getFormContext(); //Getting Value From Field Account Closed. var AccountClosed = formContext.getAttribute("accountclosed").getValue(); //Condition If Account Closed Is True. if (AccountClosed === true) { //Moving Chevron To Next Stage. formContext.data.process.moveNext(); } }
Now, if the value of field “Account Closed” is true, then after saving the record the BPF will get automatically moved to next stage by leveraging the property “data.process.moveNext()”.
Moving the BPF to Previous stage
We will use the method “formContext.data.process.movePrevious” client API for moving the Business Process Flow to the next stage. Consider the below Account record having business process flow called “Account BPF”.
Consider the below JavaScript code which is fired during OnSave event of the form record.
function BPFMove(executionContext) { //Initiated Form Context. var formContext = executionContext.getFormContext(); //Getting Value From Field Account Closed. var AccountClosed = formContext.getAttribute("accountclosed").getValue(); //Condition If Account Closed Is False. if (AccountClosed === false) { //Moving Chevron To Previous Stage. formContext.data.process.movePrevious(); } }
Now, if the value of field “Account Closed” is false, then after saving the record the BPF will get automatically moved to previous stage by leveraging the property “data.process.movePrevious()”.
CRM Crate
All In One Platform For Learning Microsoft CRM.