Dynamics CRM 2015 Applying custom subgrid with FetchXML (getElementById(“selectedGrid”) returns null)

2.2k views Asked by At

I am using Microsoft Dynamics CRM 2015 on-premise version.

I am applying a custom FetchXml to a subgrid using JavaScript.

The issue here is document.getElementById(“selectedGrid”) returns null.

I read articles says that this method is not supported anymore in 2015 Version.

My question: is there any alternative to this method?

1

There are 1 answers

2
Josh Alcorn On BEST ANSWER

This works for me, and in fact I've been able to use document.getElementById as well. If you're adding an event or something (and hooking it to onLoad), just make sure you set a Timeout because grids get loaded in via iframes after the page itself loads, so there may be some delay. I ran the below script against a datagrid that exists on our Opportunity form (this JS was hooked to onsave), and was getting "Control Found" every time.

function test()
{
    var control = Xrm.Page.getControl('grid_name');

   if (control == null)
    {
    console.log("Control not found.");
    //setTimeout(setTimeout(function() { test(); }, 3000));
    }
    else
    {
        console.log("Control found.");
    }
}