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.
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
How can I get the ID of the parent entity where this subgrid is located?