Move to Required Stage Automatically in Dynamics 365 Business Process Flow
Reference: 1
A BPF entity will be created when your BPF is created.
There are fields within this entity:
- Active Stage ID - this will contain the stage ID value of the Business Process Flow stage the application is currently in
- Application - this is the lookup to the application record
- Business Process Flow Instance ID - this is the ID of the record that will be used in a Flow action
- Status
- Status Reason
- Traversed Path - this will contain the active stage IDs the Business Process Flow has gone through in its lifecycle
If just move to the closest next or previous, can follow below simple JavaScript which is triggered on Stage Change event or Stage Selected event. Reference
form.data.process.addOnStageChange(stageChangedHandler);.
form.data.process.addOnStageSelected(stageSelectedHandler);.
function moveBPFToNextStage(context) {
var formContext = context.getFormContext();
formContext.data.process.moveNext();
}
function moveBPFToPreviousStage(context) {
var formContext = context.getFormContext();
formContext.data.process.movePrevious();
}
If need to move to a specified stage based on business requirements may refer to below two solutions.
Other useful JS api:
var currentstageId = formContext.data.process.getActiveStage().getId();
var currentStageName = formContext.data.process.getActiveStage().getName();
var selectedStageId = formContext.data.process.getSelectedStage().getId()
var selectedStageName = formContext.data.process.getSelectedStage().getName()formContext.data.process.setActiveStage(stageId);
//Get current BPF:
var
currentBPF = form.data.process.getActiveProcess();
//Get Stage quantity:
currentBPF.getStages().getLength()//Get Specified Stage, stageName, stageID.currentBPF.getStages().get(index) //index = 0, 1, 2, ..., (Stage Qty -1)currentBPF.getStages().get(index).getName()
currentBPF.getStages().get(index).getId()
//Move to the first stage
currentBPF = formContext.data.process.getActiveProcess();formContext.data.process.setActiveStage(currentBPF.getStages().get(0).getId());
//Set field read-onlyformContext.getControl("header_process_qt_approve").setDisabled(true);
//Clear field valueformContext.getAttribute("qt_shipped").setValue(null);
Note:
formContext.data.process.setActiveStage(stageId, callbackFunction);
The callbackFunction is optional.Sample:
currentBPF = formContext.data.process.getActiveProcess(); formContext.data.process.setActiveStage(currentBPF.getStages().get(0).getId(), testCallBack);
function testCallBack(param){ //The param is string type. Its value could be one of below:Value Reason success The operation succeeded. invalid There are three reasons why this value may be returned:- The *stageId* parameter is a non-existent stage ID value.
- The active stage isn’t the selected stage.
- The record hasn’t been saved yet.
unreachable The stage exists on a different path. dirtyForm This value will be returned if the data in the page is not saved. preventDefault This value will be returned if an `OnPreStageChange` event handler invokes preventDefault.
}
No comments:
Post a Comment