Skip to main content

Notifications

Announcements

No record found.

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.

  • Suggested answer
    Linn Zaw Win Profile Picture
    3,407 on at
    RE: Custom button on editable sub grid to change field values on selected records Javascript

    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!");

  • Jean Joel Kakou Profile Picture
    on at
    RE: Custom button on editable sub grid to change field values on selected records Javascript

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,933 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,801 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans