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