set the active stage in Dynamics 365 when the option set value is "yes"
function setActiveStage() {
var stageId = "{Your_Stage_Id}"; // Replace with the actual Stage ID
var field1Value = formContext.getAttribute("your_field1_logical_name").getValue();
var field2Value = formContext.getAttribute("your_field2_logical_name").getValue();
if (field1Value === true && field2Value === true) {
formContext.data.process.setActiveStage(stageId);
}
}
// Get the form context when the form is loaded
function onLoad(executionContext) {
var formContext = executionContext.getFormContext();
formContext.data.process.addOnStageChange(setActiveStage);
formContext.getAttribute("your_field1_logical_name").addOnChange(setActiveStage);
formContext.getAttribute("your_field2_logical_name").addOnChange(setActiveStage);
}
// Register the onLoad function as the event handler for the form OnLoad event
Xrm.Utility.ready(function() {
Xrm.Page.context.addOnLoad(onLoad);
});
In this updated code, the formContext
object is obtained from the executionContext
parameter passed to the onLoad
function, which is registered as the event handler for the form OnLoad event.
The rest of the code remains the same as in the previous example, utilizing the formContext
object to access form-related operations and interact with the fields and process.
Ensure that you replace "your_field1_logical_name" and "your_field2_logical_name" with the logical names of your option set fields, and "{Your_Stage_Id}" with the actual ID of the stage you want to set as active.
Comments
Post a Comment