Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Populate a many to many subgrid inside a form using Javascript

Posted on by 45

Hello I have a a many to many subgrid inside a form 

I want to populate this subgrid with some existing records using javascript

I can't use "Xrm.WebApi.createRecord" and give it the id of the form i want to link it with since it creates new records while I want to use some existing records 

How can I do that please

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Populate a many to many subgrid inside a form using Javascript

    you have two ways depending on the relationship.

    1) if the relationship is 1:N (like account-contact with parentcustomerid) you can update the records you want to associate with just the main ID (you can use Xrm.WebApi.updateRecord for example)

    2) if the relationship is N:N you must use the associate method

    (to be 100% precise, you can also use the associate method when you have a 1:N relationship, but is a preference as the result is the same)

    to generate the code you can use the tool Dataverse REST Builder (link in my signature) and if you use the associate method with Xrm.WebApi you can actually associate multiple records with a single request (by adding the records inside the relatedEntities property) if you use another JavaScript syntax (fetch, jquery, xhr) you must associate the records one by one

    hope it helps

  • Omar Bouattour Profile Picture
    Omar Bouattour 45 on at
    RE: Populate a many to many subgrid inside a form using Javascript

    Because it creates new record to the table while i want to populate the subgrid with already existing records that were already created before with already given Ids

  • Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Populate a many to many subgrid inside a form using Javascript

    why you can't use Xrm.WebApi.createRecord?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans