Hi,
CRM 2015 on-prem update 0.1.
I have a sub grid on my form showing related records from an entity called 'Items'. When the user clicks on the inline lookup to add existing items, every record of that entity is shown.
I want to use a fetch XML query to only show records in the lookup field, that meet a certain criteria. My fetch XML is correct and working, but I cannot find the correct JavaScript to filter the lookup field.
I have tried the following as an OnLoad event, but get an error "Unable to get property 'control' of undefined or null reference':
function filterItemGrid()
{
var room = Xrm.Page.getAttribute("new_meetingroom").getValue();
var roomid = room[0].id; //parameter for use in the FetchXML
var subgrid = window.parent.document.getElementById("Items");
if (subgrid != null)
{
setTimeout(filterItemGrid, 500);
return;
}
//fetch xml code
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
" <entity name='new_item'>"+
" <attribute name='new_name' />"+
" <order attribute='new_start' descending='false' />"+
" <filter type='and'>"+
" <condition attribute='statecode' operator='eq' value='0' />"+
" <condition attribute='new_room' operator='eq' value='" + roomid + "' />"+
" </filter>"+
" </entity>"+
"</fetch>";
if (subgrid.control != null)
{
subgrid.control.SetParameter("fetchXml", fetchXml);
Xrm.Page.ui.controls.get("MeetingItems").refresh();
alert("subgrid refreshed again");
}
else
{
setTimeout(filterItemGrid, 500);
}
}
Any advice would be greatly appreciated.
Thanks,
Rich