I have a simple JS function that displays or hides a subgrid based on the value of a Two Option control. After Rollup 12, I modified it as shown in http://community.dynamics.com/product/crm/crmtechnical/b/magnetismsolutionscrmblog/archive/2013/01/24/filter-sub-grid-dynamics-crm-2011-rollup-12-polaris.aspx so that the function would work, despite the fact that subgrids are now loaded later than the form's OnLoad event. However, now I'm receiving the following error: "Unable to get value of the property 'setVisible': object is null or undefined".
When debugging, I can see that the code does find the subgrid and I'm even able to use getVisible to determine its current visibility. When using setVisible in the watch window, I can see that getVisible returns the latest value I've set it to, however, that error is still thrown. Also, on the form, the subgrid is mostly hidden, but the space on the form is still taken up by the hidden subgrid and the column sort arrow is still visible (and clickable).
Has anyone else run into a similar issue? Or am I possibly running into something buggy with my environment?
function OnLoad_SubGridVisibility() { var exampleSubGrid = Xrm.Page.ui.controls.get('ExampleSubGrid'); // With Rollup 12, subgrids are no longer immediately loaded, so this function should be // called again if ExampleSubGrid is not yet available. if (exampleSubGrid == null) { setTimeout(function () { OnLoad_SubGridVisibility(); }, 500); return; } // ExampleSubGrid is available, so check new_displayexamplesubgrid and set the visibility. if(Xrm.Page.getAttribute('new_displayexamplesubgrid').getValue() == true) { exampleSubGrid.setVisible(true); } else { exampleSubGrid.setVisible(false); } }
Update: Also, when trying out that function in the Two Option control's OnChange event, it looks like it's working just fine. This seems to be an issue just with the OnLoad event.