web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filter inline lookup in subgrid

(0) ShareShare
ReportReport
Posted on by

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

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    At this time there is no supported way of doing this. Instead you will need to create an 'intersect' entity that has a 1:N relationship to your parent form and then N:1 relationhip to the Items entity. This way you can enable the 'quick create' form and have a filtered lookup.

    Hope this helps

  • Community Member Profile Picture
    on at

    That's a shame! Thanks Scott, much appreciated.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans