Getting the main form context in addOnLoad function for subgrid
Just a brief post to share this quick tip for anyone wanting to act on attributes on the main form when a subgrid is refreshed e.g. when there is at least 1 row on the grid, make an attribute read-only on the form.
When you are using the addOnLoad function ( https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/grids/gridcontrol/addonload ) to execute a function each time the subgrid is refreshed you get the subgrid context returned when invoking getFormContext() on the execution context (which is passed in automatically). You can then use getGrid() etc. to drill down and get more details about the content of the grid. However, what if you then want to perform some processing on the main form attributes, how do you get the main form context? There is a function, getParentForm() (which I am not sure appears in any of the Client API documentation) which you can invoke on the subgrid context to allow you to then access the main form attributes as you would via an onChange or onLoad event for example.
Then in the dynduo.gridRefreshed function I am going to enable/disable an attribute on the main form depending on whether there is at least one row in the grid.