Getting the Selected Record in a Subgrid Using executionContext

1 Comment
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

 

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.

 

 

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

 

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 *