In this post, we will look at how to get the selected record in a subgrid using executionContext. Note this will work on Editable grids, using the OnRecordSelect event.
Consider the scenario where we have a Contacts subgrid on the Account form:

Now, this is control is an editable grid:

Which means we can use the OnRecordSelect event:

If we add the code below to the OnRecordSelect, we will get the Id and Full Name of the record selected. Note we are getting the Id using getId() and the Name field is a result of the attribute fullname being on the subgrid:
[sourcecode language=”JavaScript”] function RunOnSelected(executionContext) {var selected = executionContext.getFormContext().data.entity;
var Id = selected.getId();
var Name = selected.attributes.getByName("fullname").getValue();
alert(Id);
alert(Name);
}
[/sourcecode]
Now when we run this, selecting a record will display the Id and Name:


Note clicking on the arrow will not run this, and instead take the user to the record.

Explore AI, agents & Microsoft technology.
I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.
Subscribe on YouTube →
How can I get the ID of the parent entity where this subgrid is located?