In Dynamics 365, locking fields on a Business Process Flow (BPF) is a method used to prevent users from editing certain fields as they work through the stages of the BPF. With a very simple function, we can prevent users to editing fields on BPFs.
In this blog post, I will share 2 different javascript functions with you. In our first function, we will only lock the fields in the BPF, while in the other function, we will be able to lock both the form and the fields in the BPF in one go.
Disable Fields on BPF
To access a field on the BPF, we need to use the header_process prefix. In other words, our attribute name, my_attribute, becomes header_process_my_attribute within this BPF. This way, we can take our field and lock it by calling the setDisabled function.
function DisableBpfFields(executionContext) {
var formContext = executionContext.getFormContext();
var bpfControl = formContext.getControl('header_process_cm_myattribute');
bpfControl.setDisabled(true);
}
Disable Fields on both Form and BPF
If the field is available on both the form and the BPF, instead of calling two separate functions, we can simply disable the entire controller of that attribute at once.
function lockAllFormFields(executionContext) {
var formContext = executionContext.getFormContext();
formContext.ui.controls.forEach(function (control, index) {
control.setDisabled(true);
});
};
For more in-depth insights and tutorials on Programming or Dynamics 365 features and customization, check out our other posts.
Leave a comment