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

Updated Subgrid informs Parent table

(0) ShareShare
ReportReport
Posted on by 515

hi

What would be the best way to update a parent table field if a subgrid on the form had been added to?

The relationship is N:N

Thanks

I have the same question (0)
  • Federico Pelliccia Profile Picture
    75 on at

    You can use the gridContext.addOnLoad(myFunction), using it in your js file. Everytime a record is added to the relative subgrid or any value is changed, the relative function will be call. But remember that it will fire also if you refresh manually the subgrid or if you sort the columns

  • Lee-Martin Profile Picture
    515 on at

    Thank you, would this work whenever the subgrid is added to? (it's not an issue if it does it every time).

    Basically I've got a Power automate flow that needs triggering whenever the subgrid is added to, so need something that will amend a hidden switch on the parent table

  • Federico Pelliccia Profile Picture
    75 on at

    Yes, it works also if a record is added to the subgrid, because it cause the refresh of the subgrid itself

  • Lee-Martin Profile Picture
    515 on at

    Brilliant

    So if I effectively used the code to update the "modified on" date field, it should trigger the flow?

  • Federico Pelliccia Profile Picture
    75 on at

    Remember that the onload Event is called also when the subgris is refreshed, so for example, also when you just load the parent form.

    My idea is that you could use an hidden variable with the number of subgrid record. When the onload event fire, you can retrieve the records and see if the total is one more than the value in the hidden variable. If so, you can update that number and trigger the flow

  • Lee-Martin Profile Picture
    515 on at

    the flow is currently set to trigger whenever the parent is updated. However it does nothing if the subgrid hasn't got additions.

    by counting the records it could be an issue if one gets deleted at the same time.

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    You will use plugin on Associate message to update field on parent entity.

    rajeevpentyala.com/.../

    I don't think you can trigger Power automate/Classic Workflow when record added in N:N relationship,

    However you can trigger Power Automate/Classic Workflow when you use Custom N:N relationship instead of using OOB N:N relationship .

    More details on Custom N:N - global.hitachi-solutions.com/.../custom-entities-n-n-relationships-dynamics-365-customer-engagement

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Lee-Martin Profile Picture
    515 on at

    Bipin Kumar

    Thank you, but the development has already been done for this, I'm just stuck trying to make the flow work.

  • Lee-Martin Profile Picture
    515 on at

     Federico Pelliccia 

    How do I use executioncontext with this in order to update the fields?

    I mean in that I need to refresh the subgrid, then tell it to calculate the difference between the hidden count field and the calculated field after I've refreshed the grid.

    gridContext.addOnLoad(myContactsGridOnloadFunction);

    For this example I would need executioncontext in myContactsGridOnloadFunction

  • Federico Pelliccia Profile Picture
    75 on at

    In the Form you have to check "Pass execution context as first parameter"


    from the docs, about addOnLoad
    "The function to be executed when the subgrid loads. The function will be added to the bottom of the event handler pipeline. The execution context is automatically passed as the first parameter to the function. See execution context for more information."

    So basically you'll have

    function myContactsGridOnLoadFunction(executionContext){
        let formContext = executionContext.getFormContext()
        let hiddelField = formContext.getAttributes('fieldname').getValue()
    }
    
    
    


    I hope i correctly understood your question

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 49 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans