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...
Answered

How to add event handler to subgrid of a form?

(0) ShareShare
ReportReport
Posted on by 190

I have a form which includes a subgrid.  I want a field in the main form to show only if there are related items in the subgrid for that particular record.  But when there are no more records (if removed manually) from the subgrid, I want to hide that same field again.  

I know how to apply javascript to event handler on the main form, but i don't know how to add it to the subgrid.  I do not see a event tab in the subgrid properties.  

As of now my scripts can only be based on main form such as onload, onsave, or on change of fields on the main form.  So if I delete a record on the subgrid, i dont want user to need to load, save the main form for the script to run.  

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi bp3378,

    Maybe you can try to use Subgrid OnLoad event: This event occurs every time the subgrid refreshes. 

    Subgrid OnLoad event (Client API reference) in model-driven apps - Power Apps | Microsoft Docs 

    Register a Function OnLoad of a SubGrid in Dynamics 365 Power Apps - Carl de Souza

    And you can use getTotalRecordCount function, it returns the total number of records that match the filter criteria of the view, not limited by the number visible in a single page.

    getTotalRecordCount (Client API reference) in model-driven apps - Power Apps | Microsoft Docs

    This blog is similar to your needs and may provide you with some inspiration:

    Working with the grid onLoad event | It Ain't Boring (itaintboring.com)

  • Suggested answer
    bp3378 Profile Picture
    190 on at

    Thank you Leah.  The onload subgrid worked for me.  I didnt get the gettotalrecordcount to work.  It only worked most of the time except when I try to delete the last record.  It seems that the after deleting, the gettotalrecordcount execute too quickly so it still reads that there is one record when there is really no more.  I tried to add a 3 sec delay but i really didnt like the delay.  So what I did is connected to the child table with  XMLHttpRequest() and selected the foreign guid that looks up to the parent record.  If there are no foreign guid for that record then that means there is no records in the subgrid, then i can do what i need to do.  

    Thanks for your  help!

  • Community Member Profile Picture
    on at

    Hi bp3378, 

    I am glad to help you, if my answer is helpful, could you click 'Yes' under the title to close the current case.

    pastedimage1655696821745v1.png

    Thanks in advance!:)

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

#2
iampranjal Profile Picture

iampranjal 36

#3
Satyam Prakash Profile Picture

Satyam Prakash 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans