web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to make Dynamics 365 editable grid read only on a field change

(0) ShareShare
ReportReport
Posted on by

Hi,

We have a business requirement to make dynamics 365 editable grid read only, we need to restrict user not to edit any more records after a field value is changed on a form, any suggestions ?

Thanks,

Shaik

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Amine Amine Profile Picture
    132 on at

    Hi,
    You can use JavaScript .

    Editable Grid support the below JavaScript events :

    OnRecordSelect

    OnSave

    OnChange

    See this :

    community.dynamics.com/.../dynamics-365-editable-grids-javascript-example

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Shaik,

    Try the code below. Register this function on change of the field.

    function DisableSubgrid(){
    // Get field value
    var value = Xrm.Page.getAttribute("AttributeName").getValue();
    
    // Get subgrid control
    var subGridCtrl = Xrm.Page.getControl("SubgridName");
    
    //Check the field value
    if(value == 'value')
    {
     // Disable the subgrid control
        subGridCtrl.disabled = true;
    }    
    }

    Hope this helps.

  • Shaik Profile Picture
    on at

    Hi Nithya - Thanks for your reply. we tried above code, its not working for Microsoft Dynamics CRM 365 editable subgrid, any other suggestions you have ?

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    Please replace the code as shown below.

    function DisableSubgrid(){
    // Get field value
    var value = Xrm.Page.getAttribute("AttributeName").getValue();
    
    // Get subgrid control
    var subGridCtrl = Xrm.Page.getControl("SubgridName");
    
    //Check the field value
    if(value == 'value')
    {
     // Disable the subgrid control
        subGridCtrl.setDisabled(true);
    }    
    }
  • Iswarya Profile Picture
    1,347 on at

    hi,

    i too have same requirement please guide to achieve this

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You need to get the context of the subgrid. Once you get the context, you can run the following code:

    function setGridReadOnly(context) {

       var entityObject = context.getFormContext().data.entity;

       entityObject.attributes.forEach(function (attribute, i) {

                   var ctrl = attribute.controls.get(0);

                   ctrl.setDisabled(true);

           }

       });

    }

    The code does not disable the subgrid, but disables all the columns/cells in the subgrid

  • Community Member Profile Picture
    on at

    Aric, I tried implementing the code, I couldn't achieve disabling the columns/cells in the subgrid. Though I have triggered the script on record select.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    What happens when you click on a row in the grid. Does it show locks next to each field, or are they editable?

    The code above does not make the subgrid read only just disabled the columns in each row.

    When you attached the code to the RecordSelect event, did you check the Pass Execution Context checkbox?

  • Verified answer
    Community Member Profile Picture
    on at

    I hope following code helps, but you have to select every record to make it non editable.

    var editableGridLoadRetryCount = 0;
    function CRMEditableGrid_DisableFields(gridName)
    {
    var editableGridControl = Xrm.Page.getControl(gridName);
    
    // addOnRecordSelect doesn't work until the grid has propertly loaded. 
    if (editableGridControl.getGrid().getTotalRecordCount() == 0
    && editableGridLoadRetryCount <= 3)
    {
    editableGridLoadRetryCount = editableGridLoadRetryCount + 1;
    setTimeout("CRMEditableGrid_DisableFields(\"" + gridName + "\")", 500);
    return;
    }
    
    // Make fields read-only in Grid.
    editableGridControl.getGrid().addOnRecordSelect(function (executionContext)
    {
    var entityObject = executionContext.getFormContext().data.entity; 
    entityObject.attributes.forEach(function (attribute, i) 
    { 
    if (attribute.getName() == "emailaddress1") { 
    var emailControl = attribute.controls.get(0); 
    emailControl.setDisabled(true); 
    break; 
    } 
    }); 
    }
    );
    }

    3365.55.png

    Thanks!!!

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Guys,

    Code is Ok, apart from syntax error :) just to be precise.

    function EditableGridReadOnly(context){

    var entityObject = context.getFormContext().data.entity;
    entityObject.attributes.forEach(function (attribute, i) {
    var ctrl = attribute.controls.get(0);
    ctrl.setDisabled(true);
    }
    )}

    On the same, where do you get grid name?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans