You have to do 2 things, for your script to work.
1) Pass execution context from the form: (see the below image for reference)
- In event handler, click on the checkbox in front of "Pass execution context as first parameter"
- As you can see i have selected "Finished ? " field first, then selected onChange -> Event Handler. Add the web resource which you have saved. Paste the function name, in your case it is "HideOrShowBPF". select both options (Enabled and pass execution context as first parameter). Click Done. Click "Save and Publish".
2) In your script (script = web resource = javascript), you have to add the execution context in the function call and also while comparing (in the if statement), compare with number value (without "" and with three =).
Just copy below script:
Updated Script:
----
function HideOrShowBPF(executionContext) {
var formContext = executionContext.getFormContext();
var AgreementType = formContext.getAttribute("uow_internationalagreementtype").getValue();
if (AgreementType === 942210001) {
Xrm.Page.ui.process.setVisible(true); //Show Business Process Flow
}
else {
Xrm.Page.ui.process.setVisible(false); //Hide Business Process Flow
}
}
----
Double check the 942210001 number in your option set, is it correct.
And this script only will run when you change the dropdown value. Means, If you have selected let's say option hide (value: 942210001) then it will hide the bpf in the form. but when you re-visit (close and reopen the form) the bpf will be there.
To hide the bpf when you open the form you have to add this same script in the on save event handler in the form's event.
If you find this answer any helpful, please, approve it.
Thanks,
Nitesh