
JavaScript Snippets to Manage BPF in Dynamics 365 CRM
Get Active Process ID
var processId = formContext.data.process.getActiveProcess().getId();
Description: Retrieves the ID of the active process.
Get Active Stage ID
var stageId = formContext.data.process.getActiveStage().getId();
Description: Retrieves the ID of the active stage within the BPF.
Get Active Stage Name
var stageName = formContext.data.process.getActiveStage().getName();
Description: Retrieves the name of the active stage.
Get Active Stage Status
var stageStatus = formContext.data.process.getActiveStage().getStatus();
Description: Retrieves the status of the active stage. The status can be either active
, inactive
, or finished
.
Set Active Stage
formContext.data.process.moveNext(function (result) {
if (result == "success") {
// Success logic here
} else {
// Error logic here
}
});
Description: Moves to the next stage in the BPF. You can use movePrevious()
to go back to the previous stage.
Get Process Stages
formContext.data.process.getActiveProcess().getStages().forEach(function (stage, i) {
console.log(stage.getId() + ": " + stage.getName());
});
Description: Retrieves all stages of the active process and logs their IDs and names.
Get Active Process Name
var processName = formContext.data.process.getActiveProcess().getName();
Description: Retrieves the name of the active BPF.
Check if BPF is Rendered
if (formContext.ui.process && formContext.ui.process.getVisible()) {
console.log("BPF is rendered");
} else {
console.log("BPF is not rendered");
}
Description: Checks whether the BPF is visible/rendered on the form.
Get BPF Control Visibility
var visibility = formContext.ui.process.getVisible();
Description: Checks if the BPF control is visible on the form.
Set BPF Control Visibility
formContext.ui.process.setVisible(true); // Set to false to hide
Description: Sets the visibility of the BPF control on the form.
Add OnStageChange Event Handler
formContext.data.process.addOnStageChange(myStageChangeFunction);
function myStageChangeFunction() {
console.log("Stage changed!");
}
Description: Adds an event handler that triggers when the stage changes.
Remove OnStageChange Event Handler
formContext.data.process.removeOnStageChange(myStageChangeFunction);
Description: Removes an event handler for the stage change event.
Get BPF Instance Status
var processInstanceStatus = formContext.data.process.getInstanceStatus();
Description: Retrieves the status of the BPF instance. Possible values are active
, aborted
, or finished
.
Get Current Process Instance ID
var processInstanceId = formContext.data.process.getInstanceId();
Description: Retrieves the ID of the current BPF instance.
Get Process ID for a Given Entity
var processId = formContext.data.process.getEntityProcesses(function (result) {
console.log(result);
});
Description: Retrieves the available BPFs for the entity and logs them.
Get Process Instances
var processInstances = formContext.data.process.getProcessInstances(function (result) {
console.log(result);
});
Description: Retrieves all BPF instances for the entity.
Set Active Process
formContext.data.process.setActiveProcess(processId, function (result) {
if (result == "success") {
console.log("Process set successfully.");
} else {
console.log("Failed to set process.");
}
});
Description: Sets the active BPF to a specific process using its ID.
Switch to a Different Process Stage
formContext.data.process.setActiveStage(stageId, function (result) {
if (result == "success") {
console.log("Stage changed successfully.");
} else {
console.log("Failed to change stage.");
}
});
Description: Switches to a different stage within the current BPF using its stage ID.