web
You’re offline. This is a read only version of the page.
close
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.

I have the same question (0)
  • Jean Joel Kakou Profile Picture
    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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 62 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Pallavi Phade Profile Picture

Pallavi Phade 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans