Clicking on a Subgrid to Open a Modal Form in Dynamics 365

4 Comments
BEFORE WE START, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

This post came at a request of a reader of this blog. She wanted to be able to click on a subgrid record and have it open in a modal form. Easy, right?

Let’s take a look at how to do this.

If you prefer to see the video, check it out on my YouTube channel:

Note, there is a limitation in that the grid needs to be an editable grid in order to access the OnRecordSelect event.

Let’s look at the Contacts subgrid on my Account form:

Let’s edit the form, and select the Contacts subgrid, then Change Properties:

We have this set to a Read-Only grid control. Select Add Control:

Let’s change this to an Editable Grid. Click Add:

We will set it to use Web. We now have an Events tab. Select it:

We see these events:

  • OnChange
  • OnRecordSelected
  • OnSave

Let’s add an OnRecordSelected event. First, let’s create a new library:

Click New:

Give it a name:

Click OK, save and publish:

Click Add:

Now the code. We will:

function RunOnSelected(executionContext) {
var selected = executionContext.getFormContext().data.entity;
var Id = selected.getId();

var pageInput = {
pageType: "entityrecord",
entityName: "contact",
entityId: Id
};
var navigationOptions = {
target: 2,
height: {value: 50, unit:"%"},
width: {value: 50, unit:"%"},
position: 1
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
function success() {},
function error() {}
);
}

Save and publish:

Then add the function to the OnRecordSelect and Add:

Select the library and function and check to pass the executionContext:

Click OK:

We’re now ready to run this. On the Account form, click on a record in the subgrid:

The record opens in a modal!

A final note, if you click the arrow it will still open the record in its own form, which is probably a good thing:

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

4 Responses to Clicking on a Subgrid to Open a Modal Form in Dynamics 365

Leave a Reply

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