Is it possible to dynamically set a filter on an editable grid from within a control event handler in the current version of Dynamics 365 Unified Interface?
I want to dynamically set a filter on an editable grid with JavaScript on Dynamics 365 9.1 Unified Interface. In this case the user selects a row from the first grid, and matching records get listed in the second grid.
There are many articles and forums about setting a filter using JS and FetchXML. They mainly use one of the 3 methods to access a grid for setting a filter.
1. Using: executionContext.getFormContext().getControl("...")
This is the supported way to access an element. However, getFormContext returns gridRowContext when called from a grid event. I was unable to access the form and the other grid this way.
2. Using: Xrm.Page.getControl("...").getGrid()
This is the deprecated method to access an element. But this way we can access another control from a triggered event, working around the issue in the 1st method. However, when accessed this way, the control doesn't give us the SetParameter method which is required to set the filter.
3. Using: window.parent.document.getElementById("...")
This is the worst, unsupported way to access an element. However, this was apparently the last resort before the Unified Interface. In the current version I naturally can't access the grid this way as the system holds controls differently, within IFrames.
I'll try keeping a global reference to the control in the Form.onLoad event, but this may not work or bring other issues.