web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to get selected rows of grid and subgrid in a editable grid list view?

(0) ShareShare
ReportReport
Posted on by 115

In a list view i set the main grid to editable and added a subgrid for an 1:n related entity. Than i added a command bar button. This should be visible whenever a parent record row or records in the subgrid are selected.

My Questions:


- Is this even possible? At the moment it seems only selected items in the subgrid seem to trigger the button to be visible?
- If its possible how to get the records/selected items by buttons javascript?
pastedimage1682089251086v1.png

I have the same question (0)
  • Arulmozhi N Profile Picture
    40 on at

    In the form editor, add a new button to the form.

    Set the Display Rule for the button to "Custom JavaScript."

    In the Custom JavaScript area, enter the following code:

    csharpCopy codefunction showHideButton() {

       var gridControl = Xrm.Page.getControl("subgrid_name");

       var selectedRows = gridControl.getGrid().getSelectedRows();

       if (selectedRows.getLength() > 0) {

           Xrm.Page.ui.controls.get("button_name").setVisible(true);

       } else {

           Xrm.Page.ui.controls.get("button_name").setVisible(false);

       }

    }

    Replace "subgrid_name" with the name of your subgrid and "button_name" with the name of your button.

    Save and publish the changes to the form.

    Open the record form and select one or more rows in the subgrid.

    The button should appear or disappear based on the number of selected rows.

    Note that this code assumes that the subgrid is on the same form as the button. If the subgrid is on a different form, you may need to modify the code to reference the correct form and control names.

  • AndreasB83 Profile Picture
    115 on at

    The editable grid is enabled on the entity level cause its a view, not a form. I cannot figure out how to get the selected rows. I added a Command Bar Button and tried to get the rows from primarycontrol or selectedcontrol reference - nothing there.

    To get the grid by name wont work because i dont know it and in html i only see sth like id="Grid67ab3cfa-a01d-13ec-81e7-648d6fe1536d_component"

  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at

    Hi,

    I'm afraid it can't be done in a supported way.

  • Verified answer
    Tamilarasu Arunachalam Profile Picture
    593 on at

    Hi AndreasB83 ,

         you can check the below article link

       

    If this answer helps you, like and verify my answer

  • AndreasB83 Profile Picture
    115 on at

    This describes best where i ended up finally BUT my original question actually was about how to grab both respectively each of the selections. Rows selcted on the top level and/or rows selected in one ore more of the embedded sub grids.

    This doesnt seem to be possible (by javascript on command buttons). You can only work with the top level records - those are provided by the primary or selected grid or SelectedItemReferences/SelectedItemReferencesId.

    I read somewehre that to achieve what i want some some could grab the collection and than post those top level record id to a plugin/flow (whatever) to, in a second query, get the related sub items.

  • Bsuycott Profile Picture
    10 on at

    This would be a candidate for either a PowerApp or Power Page experience.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 196 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 129

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans