Welcome to our blog where will be sharing tip, tricks and detailed walk-throughs covering all areas of Dynamics 365 but primarily focused on the Field Service and Project Service Apps, Scheduling and integration using Microsoft Flow and the Common Data Service (CDS). We hope you find the blog posts useful and please feel free to comment if you would like us to elaborate on any particular area. 

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.


Take this simple example, in an onLoad JavaScript function i'm adding a function to be invoked each time the grid is refreshed.

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.



201 views1 comment