Getting the Selected Record in a Subgrid Using executionContext

1 Comment

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.

 

 

Carl de Souza
Keep learning. Keep building.

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 →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

One Response to Getting the Selected Record in a Subgrid Using executionContext

Leave a Reply

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