knowledgecenter-breadcrum

Knowledge Center

03 Jul, 2022

How to lock fields on editable grid in D365 CE?

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

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

Introduction:
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.

Step-by-Step:
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 = oFormContext.data.entity;
          objEntity.attributes.forEach(function (attribute, i) {
                 if (arrFields.indexOf(attribute.getName()) > -1) {
                    let attributeToDisable = attribute.controls.get(0);
                    attributeToDisable.setDisabled(true);
                 }
          }
});
}

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.

Comment

This is a Required Field

Comments

profile image

24 days ago

Sanyal Chavadkar

Test

Reply .
profile image

25 days ago

kaustubh

Hello testing, This blog has no comments so far.

Reply .
Show all replies (1)
profile image

25 days ago

Jigneshkp

Testing3

Reply .
profile image

28 days ago

kp

qwerty

Reply .
profile image

25 days ago

kaustubhkp

Hello

Reply .
profile image

29 days ago

test demo

okay

Reply .
Show all replies (1)
profile image

29 days ago

johntest

ok

Reply .
profile image

Today

test

test

Reply .
Show all replies (1)
profile image

29 days ago

test demotest

demo

Reply .

Recent Updates

Content styling
Case Study
20 Jul, 2024

Content styling

normal paragraph Bold paragraph Italic paragraph Bold italic paragraph Highlighted paragraph colored paragraph Highlighted & colored paragraph Heading 1 Heading 2…

READ MORE
Thum
Case Study
14 Jul, 2024

Revolutionizing Build Warranty's Operations with a Scalable and Automated Dynamics 365 Solution

Customer Overview Build Warranty (BW), a leading UK-based provider of warranty solutions for the construction industry, sought a strategic partner…

READ MORE
test
Blogs
16 Aug, 2023

Power BI - Test 1

asfwreg

READ MORE