Nested Editable Grid in Dynamics 365: Read-Only Guide
Image Source: Shutterstock.com
Dynamics 365
Sep 27, 2023 6:12 PM

Nested Editable Grid in Dynamics 365: Read-Only Guide

by HubSite 365 about Benedikt Bergmann [MVP]

Microsoft Business Applications MVP | Power Platform Consultant at CRM-Konsulterna

External Blog Post
Citizen Developer

Dynamics 365Learning Selection

Discover how to create a read-only nested editable grid in Microsoft Dynamics 365 without HTML or line breaks, in this experts guide to SEO.

Benedikt Bergmann wrote an insightful blog post on making a nested editable grid read-only in Dynamics 365, a requirement for one of his projects. He aimed to display subgrid information from a table two relations away, with no provision for direct editing. In responding to that, Benedikt devised an approach wherein he used editable grid but made sure it only displayed information and was not editable directly.

He framed an exemplary scenario where an event registration is built in Dataverse. This involves multiple "Demo Attendee" rows associated with a custom "Demo Event" table related to a contact. Every contact here is linked to an Account. The goal, thus, was to display all "Demo Attendee" rows associated with the account in question.

Benedikt’s initial consideration was to craft a separate PCF (Power Apps Component Framework) for this requirement. The default Out-Of-The-Box (OOB) editable grid didn't completely solve the problem. After seeking ideas within the Power Platform Level Up discord group, he came across an alternative solution that was easier to implement. It involved adding a JavaScript to the "onRecordSelected" event, instead of recreating all the functionality with a PCF.

The JavaScript function inactivates all fields, both at the first and second level. He confirmed that "getEventSource" function returns an entity when called from the onRecordSelected event. Therefore, all attributes and related controls could be looped through and disabled. This function, once written, should be uploaded as a Webresource.

To make this nested grid read-only, the script needs to be added to the event, meaning our script must be configured rightly. As Benedikt noted, this scripting configuration needs to be done in the classic UI because event configuration on subgrids isn't yet available in the maker portal. He further demonstrates how to configure the script for the first and second level of the subgrid.

Interestingly, Benedikt concludes that with a small script and some configuration, a nested editable grid can be rendered read-only, a method much easier and faster than creating a PCF for it. For more insights and tactics, follow this link.

A Unpacking

The ability to display subgrids of information, specifically from tables with multiple relational stages, is a function very much valued. The concept of rendering the grid data uneditable, directly on the display or grandparent, is an exciting point to revise. It is a stepping stone towards achieving tailored functionality within data platforms. The center of focus here is Microsoft's Dynamics 365, an expansive platform involving Power Apps, dataverse, and the likes, forming a solid foundation for a custom built event registration scenario, as proposed in the blog post.

Read the full article Read-only nested editable grid in Dynamics 365

Dynamics 365 - Nested Editable Grid in Dynamics 365: Read-Only Guide

Learn about Read-only nested editable grid in Dynamics 365

In this article, we delve into the fascinating world of creating a read-only nested grid that can be edited when using Dynamics 365. This blog post is based on a task my coworker brought to my attention. In one of our client's projects, we had to design a subgrid that could display details from a table that was two relations away. Here, we will provide a step-by-step guide on how to structure a nested editable grid in the dataverse.

One of our customers had a condition where they had to display information from a table with two relationships away. This is achievable through the editable grid. Nevertheless, the subgrid gets editable. In our client's case, however, they wanted to just visualize the information and not make it editable on the grandparent.

For the purpose of this article, let's envision we have an Event registration developed in the dataverse. A user can have numerous “Demo Attendee” rows that relate to a different custom table named “Demo Event”. Each user is connected to an Account. We want to exhibit all “Demo Attendee” rows associated with the Account in question. Consequently, our table structure is as shown in the diagram.

Initially, I thought that the OOB editable grid could not solve our dilemma. Therefore, we were left with no choice but to build a Power Apps Component Framework for it. After a bit of digging, I wasn’t able to find any PCFs that did what we needed. It was strange considering we couldn't possibly be the first ones facing such an issue. I then sought help from the Power Platform Level Up discord group, which I recommend you join as it is an excellent platform for Power Platform developers to discuss questions and offer solutions.

A user there, hajhassan94, suggested adding a JavaScript function to the “onRecordSelected” event. As this is easier than recreating all the potential features with a PCF is what we will delve into this article.

Let's have a look at how the implementation would look like. We first need a small JavaScript function that will inactivate all fields. I reviewed numerous other blogs, such as those by Nishant and Pawel Gradecki. They did a similar thing but only deactivated one specific field and have not worked on the second level.

The function mentioned will shut down all fields and can be utilized both on the first and second level. First, you can see the TypeScript code and then the plain JavaScript code. Following the MS docs, the “getEventSource” function returns an entity when summoned from the onRecordSelected event. As a result, we can cast it to Event in TypeScript and presume there are attributes in JavaScript. Afterward, the script will run a loop through all attributes and the connected controls and disable those. The script needs to be uploaded as a Webresource and named as shown.

I expect the nested subgrid to be configured as it should. In order to integrate our script in the event and thereby render the nested grid read-only, we have to establish it. However, it needs to be done in the classic UI since event configuration on subgrids is unavailable in the maker portal. Consequently, open the form in question and select “Switch to classic”.

In the new window, we'll navigate to the Events tab by double-clicking on it. Subsequently, add a library by clicking "+ Add", and search for your web resource and add it as a library. After you've done that, the Events tab should look something similar to this.

To incorporate the script for the first level of the subgrid, on the Events tab we scroll down and select the first level table in the “Entity”, and “onRecordSelected” as the event. Then click “+ Add” to insert a new function to the event. And on the next screen select the library just added, inscribe the name of the function and tick the box to pass the execution context to the function.

For the second level, we perform the exact same steps as we did for the first level only we select the table from the second level. Ultimately, save and publish the form and you should be good to go.

To sum it all up, forming a nested editable grid that is read-only is as simple as having a minor script and certain configurations in place. This is much more efficient than creating a PCF.

I'm sure this blog post will be of great assistance to you when implementing a read-only nested editable grid in the dataverse. Do feel free to contact me if you come across any additional questions or input.

More links on about Read-only nested editable grid in Dynamics 365

Read-only nested editable grid - Benedikt's Power Platform Blog
Feb 22, 2023 — This blog post will explain how to create a read-only nested editable grid in Dataverse. As well as touch on some alternatives.
Use Editable Grid control in Dynamics 365 Customer ...
Feb 15, 2022 — At runtime, users can toggle between editable grids and read-only grids. ... grid view, and then select the entity and view for the nested grid.
Read-only nested editable grid - Dynamics 365 Community
Feb 22, 2023 — All it takes to make a nested editable grid read-only is a small script and some configuration. This is much easier and faster than creating a ...

Keywords

Dynamics 365 nested editable grid, Read-only grid Dynamics 365, Dynamics CRM editable grid, Dynamics nested grid, Dynamics 365 grid customization, Microsoft Dynamics read-only grid, Editable nested grid Dynamics, Dynamics 365 grid editing features, Nested grid read-only options, Custom grid Dynamics 365.