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 511

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

  • Federico Pelliccia Profile Picture
    75 on at
    RE: Updated Subgrid informs Parent table

    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

  • Lee-Martin Profile Picture
    511 on at
    RE: Updated Subgrid informs Parent table

     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

  • Lee-Martin Profile Picture
    511 on at
    RE: Updated Subgrid informs Parent table

    Bipin Kumar

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

  • Suggested answer
    Bipin D365 Profile Picture
    28,961 Moderator on at
    RE: Updated Subgrid informs Parent table

    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
    511 on at
    RE: Updated Subgrid informs Parent table

    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.

  • Federico Pelliccia Profile Picture
    75 on at
    RE: Updated Subgrid informs Parent table

    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
    511 on at
    RE: Updated Subgrid informs Parent table

    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
    RE: Updated Subgrid informs Parent table

    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
    511 on at
    RE: Updated Subgrid informs Parent table

    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
    RE: Updated Subgrid informs Parent table

    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

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... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,011 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans