Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

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

  • lawix10 Profile Picture
    lawix10 330 on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    Hello Aric, I have a requirement to Validate an editable grid, but I cant use the set notification method.

    function validatePhoneNumber()
    {
    var addressSubgrid= Xrm.Page.getControl("AddressDetails").getGrid();
    var selectedRows = addressSubgrid.getSelectedRows();
    var phonenumber = selectedRows.get(0).getData().getEntity().getAttributes().get("new_phonenumber").getValue();
    //var control = selectedRows.get(0).getControl("new_phonenumber");
    console.log (phonenumber); // correct
    control.setNotification('Wrong Phone', 'ValidationAlert'); //wrong
    }


    Using the Alert Dialog alone wont validate.

    I am not using the execution context method here.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    Hi Shaik,

    You might can have a look on below blog: 

    https://crmbusiness.wordpress.com/2015/06/12/crm-2013-disabling-a-subgrid/#comment-25533

    Thanks,

    Anuj Govil

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    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?

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    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!!!

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    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?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    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.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    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

  • Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    hi,

    i too have same requirement please guide to achieve this

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    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);
    }    
    }
  • Shaik Profile Picture
    Shaik on at
    RE: How to make Dynamics 365 editable grid read only on a field change

    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 ?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans