How to lock fields on a Form and BPF (Business Process Flow)

Power Dynamite
3 min readOct 31, 2023

Locking fields on a form and Business Process Flow (BPF) is a common requirement in applications like Microsoft Dynamics 365. Here’s how you can lock fields in both scenarios:

1. Lock Business Process Flow fields

I’m now developing a JavaScript function code that will lock the business process flow fields, as seen in the highlighted areas of the figure.

The function below locks all fields that have the word “header_process_” in them. By doing this, it is ensured that the forms fields are not locked rather, only those that are in the business process flow are.

function lockAllBPFFormFields(executionContext) {
var formContext = executionContext.getFormContext();
formContext.ui.controls.forEach(function (control, index) {
var control Name = control.getName();
if (controlName.indexOf("header_process_") !== -1) {
control.setDisabled(true);
}
});
}

The lockAllBPFFormFields JavaScript function is intended to disable particular fields on a model-driven app form associated with a business process flow. Here is a condensed description of the code:

1. It takes an executionContext parameter, which provides access to the form context.

2. It obtains the form context using executionContext.getFormContext().

3. The code then iterates through all the controls (fields) on the form using a forEach loop.

4. For each control, it checks its name using control.getName().

5. If the control’s name contains “header_process_” (indicating it’s related to a business process flow) it disables the control by setting it to true using control.setDisabled(true).

The next action is to insert the JavaScript code into the form and create an event registration for it during the form’s loading process.

The first step is to include your JavaScript library in the form. Then, you should choose the “on load” event type and insert the custom function you wrote in your JavaScript code into the function box and pass execution context as first parameter. After completing these procedures, it’s crucial to save and publish the modifications.

Your business process fields have been effectively disabled if you follow all of the previously described instructions.

2. Lock Form fields only

All fields that do not contain the word “header_process_” are locked by the function below. This makes sure that the Business Process Flow’s fields are not locked, just those that are on the form.

function lockAllFormFields(executionContext) {
var formContext = executionContext.getFormContext();
formContext.ui.controls.forEach(function (control, index) {
var controlName = control.getName();
if (controlName.indexOf("header_process_") === -1) {
control.setDisabled(true);
}
});
};

3. Lock Business Process Flow and form fields

If you need to lock the entire form, the function below is an excellent option because it locks all header fields and duplicate fields on the form, as well as the Business Process Flow.

function lockAllFormFields(executionContext) {
var formContext = executionContext.getFormContext();
formContext.ui.controls.forEach(function (control, index) {
control.setDisabled(true);
});
};

Thank You!!!

--

--