GETTING THE SELECTED RECORD IN A SUBGRID USING EXECUTIONCONTEXT

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:

function RunOnSelected(executionContext) {
   var selected = executionContext.getFormContext().data.entity;
   var Id = selected.getId();
   var Name = selected.attributes.getByName("fullname").getValue();
   alert(Id);
   alert(Name);
}

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.

GETTING THE SELECTED RECORD IN A SUBGRID USING EXECUTIONCONTEXT

https://thepowerappsninja.com/

https://www.youtube.com/@powerappsninja

Leave a Comment

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