Code Snippets

  • Lock Form Fields
    JavaScript
    This script locks all fields on a Dynamics 365 form, excluding subgrids, to prevent user modifications during execution.
This script locks all fields on a Dynamics 365 form, excluding subgrids, to prevent user modifications during execution.

// Function to lock all fields on the form function lockAllFields(executionContext) { // Get the form context var formContext = executionContext.getFormContext(); // Retrieve all attributes (fields) on the form var attributes = formContext.data.entity.attributes; // Iterate through all attributes to lock them attributes.forEach(function (attribute) { // Get the control associated with the attribute var controls = attribute.controls; // Lock each control associated with the attribute controls.forEach(function (control) { if (control.getControlType() !== "subgrid") { // Do not lock subgrids control.setDisabled(true); } }); }); }