web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Bsuycott Profile Picture
    10 on at
    RE: How to get selected rows of grid and subgrid in a editable grid list view?

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

  • AndreasB83 Profile Picture
    115 on at
    RE: How to get selected rows of grid and subgrid in a editable grid list view?

    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.

  • Verified answer
    Tamilarasu Arunachalam Profile Picture
    560 on at
    RE: How to get selected rows of grid and subgrid in a editable grid list view?

    Hi AndreasB83 ,

         you can check the below article link

       

    If this answer helps you, like and verify my answer

  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at
    RE: How to get selected rows of grid and subgrid in a editable grid list view?

    Hi,

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

  • AndreasB83 Profile Picture
    115 on at
    RE: How to get selected rows of grid and subgrid in a editable grid list view?

    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"

  • Arulmozhi N Profile Picture
    40 on at
    RE: How to get selected rows of grid and subgrid in a editable grid list view?

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 147

#2
DAnny3211 Profile Picture

DAnny3211 134

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans