Knowledge Center

03 Jul, 2022

How to lock fields on editable grid in D365 CE?

Posted on 03 Jul, 2022 by Admin, Posted in Dynamics 365 Power Platform Dynamics-365 Sales

How to lock fields on editable grid in D365 CE? Blogs

Recently I got a situation where I need to lock the fields in editable grid. I tried to find the solution on internet. I found a suggestion as to use business rule having scope to “Entity”. But it did not worked as it was locking the fields on forms also. Then I created another business rule having scope to “All Forms” to unlock fields. But it was unlocking the fields on grid also. So, decided to add a script on view load, but there is no event for that. There are only onSave and onRecordSelect handlers for views. Then I learned that whenever we try to edit a field the records automatically get selected. So, I can achieve desired result by adding script on onRecordSelect event handler.

In this blog I am going to explain how to lock fields on editable grid.

Create a newscript web resource and add below code
function fnLockFields(executionContext) {
      let oFormContext = executionContext.getFormContext();
      if (oFormContext) {
          let arrFields = ["subject", "regardingobjectid", "ownerid"];
          let objEntity =;
          objEntity.attributes.forEach(function (attribute, i) {
                 if (arrFields.indexOf(attribute.getName()) > -1) {
                    let attributeToDisable = attribute.controls.get(0);

Now, go to Settings -> Customization -> Customize the System -> Entities(select your entity) -> Events -> Add Web resource library->Add OnRecordSelect event handler and add function name.

Pass the execution context as first parameter.
Save and publish.
Now, when you try to edit any locked attribute, selected attributes will be locked.


This is a Required Field



profile image

16 days ago

Sanyal Chavadkar


Reply .

Recent Updates

02 Apr, 2024

Sales accelerator in D365 Sales

Introduction: In this blog we will see how Sales accelerator works and also how 'My work list' displays the work items.…

01 Apr, 2024

How to Create Entitlement in D365 Customer Service

In this blog we will learn about what is Entitlement and how to create it. 1)what is Entitlement? Entitlement is…

22 Mar, 2024

How to Create Product Catalog in Dynamics 365 for Sales - Part 1

In this blog series we will learn how to set up a product catalog in D365 Sales. The Product Catalog contains…