How to Trigger JavaScript on an Editable Grid in Dynamics 365

Adam Murchison, 11 April 2018

Editable grids are an awesome new feature within Dynamics 365, if you haven’t had a chance to play around with them then I suggest you do. Also, check out my blog: Introduction to Editable Grids in Dynamics 365.

Inside the editable grid the JavaScript on the main form is not mimicked within. To apply your own JavaScript on an editable grid is very easy, in this blog I’m going to show one example of locking specific fields within the editable grid (In this case; the registration status). The reason I’m using this example is because there is no out of the box functionality to make a field read only in an editable grid.

image

First, let’s create the JavaScript we are going to apply to lock an array of fields in CRM. It is a very simple method:
This method loops through each field on the editable grid and if it's in the ‘disabledFields’ array then disable the field.

image

Then add this JavaScript as a web resource or to an existing web resource.

Secondly go to the form you’d like to apply JavaScript to, for this example I’d like to be able to edit Registrations on an Event record i.e. on the Registration sub-grid.

image

Once the Editable Grid has been added to the SubGrid, the Events tab will appear and this is where you can add in the web resource you created earlier and ensure the Event trigger is OnRecordSelect. There are other events to trigger the JavaScript on such as ‘OnChange’ which is triggered when a specific field is changed within the editable grid and ‘OnSave’ which triggers the JavaScript when the record is saved.

image

image

Next add in the function and ensure that you are passing in the execution context as the first parameter.

image

Easy as that, as shown in the screenshot above you can now see that the Registration Status is locked. Now you have the power to enable JavaScript on an editable grid.