• 2 Responses

    How to lock fields on editable grid in D365 CE?

    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:

    1. Create a new script web resource and add below code
    2. 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);
                       }
                }
      });
      }
      
    3. 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.
    4. Pass the execution context as first parameter.
    5. Save and publish.
    6. Now, when you try to edit any locked attribute, selected attributes will be locked.

  • Subscribe
    Notify of
    guest
    2 Comments
    Oldest
    Newest Most Voted
    Inline Feedbacks
    View all comments
    Piyush
    Piyush
    1 year ago

    In my case,its nested editable grid,so when i click on record it opens the related record in child grid,Can we make that readonly as well.

    Sair
    Sair
    1 year ago

    Or you can use a business rule to lock the field (Scope : enity)

WANT QUICK D365 IMPLEMENTATION?

Let started with our D365 Quickstart package and get onboard within 7 days!

I'M INTERESTED!
LATEST POSTS
© Copyright 2024 Nebulaa IT Solutions LLP. All Rights Reserved.
Download
Brochure