Hi everyone,
I need some help with my code as the implementation of applying custom FetchXml to a subgrid has appeared to have changed in CRM 2011 to CRM 2013. Please note this is NOT the issue of setParameter vs SetParameter casing as I keep finding all over the
net. My issue is how to reference the subgrid and call the SetParameter method at all.
Here is my code:
function uc_addCaseFilterToCaseGrid() {
var contactGuid = Xrm.Page.data.entity.getId();
//create a filter xml
if (contactGuid != null)
{
var filter = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
filter += "<entity name='uc_crecord'>";
filter += "<attribute name='uc_casemanager' />";
filter += "<attribute name='uc_cindividual' />";
filter += "<attribute name='uc_rindividual'/>";
filter += "<filter type='or'>" +
"<filter type='or'>" +
"<condition attribute='uc_casemanager' operator='eq' value='" + contactGuid + "'/>" +
"<condition attribute='uc_cindividual' operator='eq' value='" + contactGuid + "'/>" +
"<condition attribute='uc_rindividual' operator='eq' value='" + contactGuid + "'/>" +
"</filter>" +
"</filter>" +
"</entity>" +
"</fetch>";
//add filter
//var caseGrid = Xrm.Page.getControl("gPR");
//var caseGrid = Xrm.Page.ui.controls.get("gPR");
var caseGrid = document.getElementById("gPR").control;
if (caseGrid == null)
{
//The caseGrid hasn't loaded, wait 1 second and then try again
setTimeout(uc_addCaseFilterToCaseGrid, 3000);
return;
}
caseGrid.control.SetParameter("fetchXML",filter);
caseGrid.control.Refresh();
}
}
This code does not work because the bold, italisized line is causing me a problem.
If I use getElementByID (not recommended, and not the approach I'd like to take) the code SetParameter executes as expected.
However, I want to use the following to set the variable:
var caseGrid = Xrm.Page.getControl("gPR");
as I want to ensure future support. But when I call SetParameter I get an error "Object doesn't support property or method 'SetParameter'". What gives?
I've tried the following:
caseGrid.control.SetParameter("fetchXML",filter);
caseGrid.SetParameter("fetchXML",filter);
Xrm.Page.getControl(gPR)._control.get_innerControl()._element.control.SetParameter("fetchXML",filter);
I've tried setParameter and SetParameter and both yield the same result.
I'm going around the bend trying to figure it out - is it possible that you just can't use SetParameter anymore in CRM 2013 (but you could in 2011)? If so, how else can I supply the fetchXml for a subgrid?
Tested in IE11, CRM 2013 Update Rollup pack 1 + Service Pack 1.
Thanks for your time.