1
votes

I am using crm dynamics 365 on-permises

I have BPF (business process flow)

and I want to move forward to the last stage using javascript , but it moves only one stage with this code :

for (var i = 0; i < Xrm.Page.data.process.getActivePath().getLength(); i++) {
   currentStage = Xrm.Page.data.process.getActiveStage();
   if (currentStage && currentStage.getName() == "lastStage") return;
   Xrm.Page.data.process.moveNext();
}
3

3 Answers

2
votes

moveNext() is asynchronous so you must provide it with a callback function to evaluate its result:

Xrm.Page.data.process.moveNext(callbackFunction);

From Microsoft documentation:

Remarks: An optional function to call when the operation is complete. This callback function is passed one of the following string values to indicate whether the operation succeeded.

  • success: The operation succeeded.
  • crossEntity: The next stage is for a different entity.
  • end: The active stage is the last stage of the active path.
  • invalid: The operation failed because the selected stage isn’t the same as the active stage.
  • dirtyForm: This value will be returned if the data in the page is not saved.
0
votes

We can achieve this by either of below 2 ways:

1.If you know the last stage, set it using the following method in JS on your conditional checkpoints

Xrm.Page.data.process.setActiveStage(stageId, callbackFunction);

2.Or using the addOnStageSelected method to add your own handler & call the following method to call the subroutine till the needed stage is attained

Xrm.Page.data.process.addOnStageSelected(handler);
0
votes

When a user makes a decision in my BPF, for example a denial of a request...they select disapprove from the option set, and then I use an OOTB workflow on the BPF entity to set the active stage.

The workflow then kicks off a script that "hard refreshes" the form by setting a refresh Boolean (two option field) to true.

The script consists of a call to:

Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId()) 

and the active stage is set for the user after the form reloads. Even if you use the javascript to set the active stage...that action WILL NOT show up until the form is refreshed. In this manner, you automate the refresh process, and give the instant gratification that your users and PM want from you.

I actually have the openEntityForm call on a 1500ms setTimeout() function. I hope this helps, it's been good for my needs as far as redirecting the user to a desired BPF stage.