Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

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

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

  • Bsuycott Profile Picture
    Bsuycott 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
    AndreasB83 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
    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
    XM-22040801-0 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
    AndreasB83 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
    Arulmozhi N 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans