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.
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.
Thanks in advance!:)
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!
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)
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,902 Super User 2024 Season 2
Martin Dráb 229,316 Most Valuable Professional
nmaenpaa 101,156