Softstuff Consulting
My occasional musings of a technical nature
  • Send us a message
  • About Softstuff Consulting
  • Privacy Policy
  • Main Website
Dynamics365 , JavaScript

Make fields read-only in a Dynamics editable grid

by Ian Blair March 2, 2020 No Comments

One of the newish controls in Dynamics365 is the editable grid. This provides the user with a simple way of bulk editing, and for the person configuring the screens it a very simple change that brings lots of useful additional functionality with a few mouse clicks.

The only issue is that almost all the fields can be edited, and this can lead to some issues with data integrity.

To change a normal grid into an editable grid, select the grid properties and click “Add Control” and then select “editable Grid” from the list and then select where the editable grid will apply.

Editable Grid Configuration
Editable Grid Configuration

To keep the like for like functionality you will need to switch off the “Group by Column” option, so this will mean that the editable grid will behave almost exactly like the existing grid except almost all the fields can be modified inside the grid.

Mostly likely you won’t want all the fields editable, and at the moment the only way to do this is with a small piece of JavaScript.

Create the .js file, or add the code to an existing one.

function gridRowSelected(context) {
    var fieldsList=["new_field1","new_field2"];
    context.getFormContext().getData().getEntity().attributes.forEach(function (attr) {
        var fld = attr.getName();
        if (!fieldsList.includes(fld)) {
            attr.controls.forEach(function (c) {
                c.setDisabled(true);
            });
        }
    });
}

In the code above add the fieldnames that you wish to be editable, as by default any fields that aren’t in this list will be made disabled.

This is done in fieldsList=[“fieldname1″,”fieldname2″,”fieldname3”];

Next the code needs to be added to the grid itself so that it fires on the OnRecordSelect event.

 

Connect code to editable grid
Connect code to editable grid
Grid Code Attachment
Grid Code Attachment

Ensure the Execution Context gets passed as the first parameter as the Dynamics V9 code needs this to be able to access the form elements.

Next publish the changes and test.

  • Previous Add a responsive logo to a bootstrap web application5 years ago
  • Next Make JavaScript a little more readable5 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to make your Powershell scripts more annoying
  • What motherboard is in my PC
  • A Dynamics365 plugin thought experiment
  • Registering a Dynamics365 plugin and I get an error
  • Going back in time with Dynamics365

Categories

  • Bootstrap
  • C#
  • CSS
  • Dot Net Core
  • Dynamics365
  • JavaScript
  • Powershell
  • T-SQL
  • Thoughts
  • VBScript
  • Visual Studio
  • Windows
  • Xamarin

Recent Comments

  • S0ftStuffB055 on Call a Dynamics365 workflow from JavaScript
  • Siva on Call a Dynamics365 workflow from JavaScript
  • TC Sharpe on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • BigOwl on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • CRMGod on Access a Dynamics365 embedded webresource

Archives

  • January 2021
  • May 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • June 2019
  • May 2019
  • February 2019
2025 Softstuff Consulting. Donna Theme powered by WordPress
  • Twitter