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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Custom button on editable sub grid to change field values on selected records Javascript

(0) ShareShare
ReportReport
Posted on by

Good day Community

I am hoping I can get some guidance here.

I have created a custom button in Ribbon workbench and have successfully added it to an editable subgrid with rules to show when 1 or more records are selected in the subgrid and to hide the buttons when there are no records selected.

My problem now is I can't seem to get the JavaScript to work when clicking on the button. What needs to happen, is when I select the button, it needs to change a value on the records selected in the subgrid.

Can someone please help me here with a sample of Javascript that I can look at and see where I am going wrong?

Thanks in advance.

  • Jean Joel Kakou Profile Picture
    Microsoft Employee on at

    Hello Tyler,  

    Thank you for posting on community forum.

    You will have to debug the issue by doing the following:

    Is the code JS working without any rule on normal selected record even? You can check the console log is there is any issue.

    You will have first to remove the hide and show rule and see if your JavaScript is working without

    For the sample , you can find it here:

    www.briteglobal.com/.../

    therapyincode.wordpress.com/.../

    Let me know if you need anything.

  • Suggested answer
    Linn Zaw Win Profile Picture
    3,407 on at

    You will have to pass the SelectedControl as CrmParameter Value as shown in the blog post below. 

    https://debajmecrm.com/getting-form-context-from-sub-grid-ribbon-button-in-dynamics-v9-0-gotchas/

    Then, get the gridContext.

    var grid = selectedControl.getGrid();

    Once you get the gridContext, you can call getSelectedRows()

    https://docs.microsoft.com/powerapps/developer/model-driven-apps/clientapi/reference/grids/grid/getselectedrows?WT.mc_id=DX-MVP-5003873

    and loop through the GridAttribute for each selected record.

    https://docs.microsoft.com/powerapps/developer/model-driven-apps/clientapi/reference/grids/gridattribute?WT.mc_id=DX-MVP-5003873

    Sample code to set the value of first selected row

    grid.getSelectedRows().get(0).getData().getEntity().attributes.get("xyz_name").setValue("Updated!");

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 42 Super User 2026 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 39 Super User 2026 Season 2

#3
Travis South Profile Picture

Travis South 27

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans