Events in Dynamics 365 Editable Grid

By | December 29, 2016

Introduction:

Dynamics 365 was introduced with lots of useful new features and improvements over the previous versions. Editable grid is one of the most requested feature by Dynamics CRM users. Editable grid provides the ability to register events, so you can execute your business logic.

Let us explore this feature in detail:

You can register Data Events or UI Events as seen in the screenshot below;

1

Different events that can be registered are:

OnChange:

Similar to the OnChange event of the other controls, this event fires when the value of a cell in the grid is changed and you tab out of it. Note tab out is important for the event to fire. This event will also auto-fire when a setValue call is used to set the value of any column in the grid.

OnRecordSelect:

This will fire when the user moves across rows in the grid. This will not fire if you select multiple rows from the grid.

OnSave:

OnSave automatically triggers on the following

  • Save button on the editable grid is explicitly clicked.
  • You navigate across rows in the grid.
  • Any action like sort, filter, grouping that causes the grid to reload/refresh.

Example using Onchange:

We can use JavaScript to perform a business logic. Suppose we have a requirement to calculate the margin % and set it into the margin field in Opportunity. We have developed the JavaScript and added on the form. To achieve the same in Editable grid, we have to register the JavaScript, OnChange of the Price and Cost fields. Now, when the user sets or updates the Price or Cost, then our script will fire, calculate the margin and populate it into the margin field of Opportunity.

In the below screenshot, we have added the required scripts and registered the Price and Cost field OnChange event;

2

The code to achieve this functionality is mentioned below;

When user updates the price or cost, then the margin will auto populate as shown in below screenshot.

3

Example using OnRecordSelect

We have another requirement where if the Margin is less than ‘0’ then we want to alert the user. To achieve this, we developed the script and registered OnRecordSelect event as shown in below screenshot.

4

When the user selects the grid row, the script will fire if the margin is less than ‘0’ and it shows an alert, as shown in the below screenshot.

5

Note: If we have a business rule associated with the cost and price field, they would be executed as well.

Conclusion:

Editable grids in Dynamics 365 enable users to edit the data, right in the grid, with few clicks! Events in editable grids add to the functionality of this feature.

Done with successful Dynamics 365 implementation? Now try User Adoption Monitor for evaluating its User Adoption!

Leave a Reply