RE: How to set value in custom field on basis of Business process flow stage
Hi Partner,
You can try to use js code in the onload event, it can directly update field value based on actived stage name.
In my example, opportunity has a bpf, which named opportunity sales process and has four stage.

1.write js code.
function formonload() {
Xrm.Page.data.process.addOnStageChange(getStage); // Trigger the function when move to next stage.
getStage();
}
function getStage() {
var activeStage = Xrm.Page.data.process.getActiveStage();
var stagename = activeStage.getName();
switch (stagename) {
case "Qualify":
Xrm.Page.getAttribute("new_stage1").setValue(0);
break;
case "Develop":
Xrm.Page.getAttribute("new_stage1").setValue(1);
break;
case "Propose":
Xrm.Page.getAttribute("new_stage1").setValue(2);
break;
default:
Xrm.Page.getAttribute("new_stage1").setValue(3);
}
}
2.Go Settings > Customizations > Customize the system > web resource to add it.


3.Go Settings > Customizations > Customize the system > entities > opportunity > forms > open main form to click form porperties.

4.Add web resource you just created.

4.test.

Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.