var Sdk = window.Sdk || {};
(function () {
//A global variable to store information about enabled business processes after they are retrieved asynchronously
this.enabledProcesses = [];
// Code to run in the OnLoad event
this.formOnLoad = function (executionContext) {
// Retrieve the formContext
var formContext = executionContext.getFormContext();
//Determines if there is currently an active Bussines process flow.
if(formContext.data.process.getActiveProcess()){
return;
}
// Retrieve Enabled processes
formContext.data.process.getEnabledProcesses(function (processes) {
//Move processes to the global Sdk.enabledProcesses array;
for (var processId in processes) {
Sdk.enabledProcesses.push({ id: processId, name: processes[processId] })
}
console.log("Enabled business processes flows retrieved and added to Sdk.enabledProcesses array.");
//Write the values of the Sdk.enabledProcesses array to the console
if (Sdk.enabledProcesses.length < 0) {
console.log("There are no enabled business process flows for this table.");
}
else {
console.log("These are the enabled business process flows for this table:");
//Determines if the current entity has only one enabled Bussines process flow.
if(Sdk.enabledProcesses.length === 1){
//Sets the BPF in the current entity as the active BPF.
var enabledProcessId = Sdk.enabledProcesses[0].id;
formContext.data.process.setActiveProcess(enabledProcessId)
}
}
});
};
}).call(Sdk);