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 the subgrid inline lookup

(0) ShareShare
ReportReport
Posted on by 233

Hello,

I am not able to filter the subgrid inline lookup based on the customer  i tried by using the javascript,i.e, by using document.getElementById ,I am getting error below is my code please any body suggest me

function setSubgridLookupFiltering()
{
debugger;
var subgridAddButtonId = "AssetRegister";

//Try to get the element from both the current and the parent document.
var subgridAddButton = document.getElementById(subgridAddButtonId) || window.parent.document.getElementById(subgridAddButtonId);

//This script may run before the subgrid has been fully loaded on the form. If this is the case,
//delay and retry until the subgrid has been loaded.
if (subgridAddButton == null) {
setTimeout(setSubgridLookupFiltering, 2000);
return;
}

//Local function to retrieve the lookup control and apply the filter. We will queue this function in the click event handler of the
//Add button's click event.
var getSubgridLookupAndAddFilter = function() {
var subgridLookup = Xrm.Page.getControl("lookup_AssetRegister");

//Delay and retry until we can locate the lookup.
if (subgridLookup == null) {
setTimeout(getSubgridLookupAndAddFilter, 200);
return;
}

//This is a custom property we are tagging on to the lookup control to ensure that we will
//apply the custom filter only once when the Add button is first clicked.
if (subgridLookup.customFilterAdded) {
return;
}

subgridLookup.addPreSearch(function() {
//Standard logic to build up the filter query string
var filterQuery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='new_assetregister'>"+
"<attribute name='new_name' />"+
"<attribute name='createdon' />"+
"<attribute name='new_assetregisterid' />"+
"<order attribute='new_name' descending='false' />"+
"<filter type='and'>"+
"<condition attribute='new_customer' operator='eq' uiname='Erbrains test' uitype='account' value='{3539838C-8675-E911-A956-000D3AF0694E}' />"+
"</filter>"+
"</entity>"+
"</fetch>";

//Standard call to add filter to the lookup control
subgridLookup.addCustomFilter(filterQuery, "new_assetregister");
});

//Mark the fact that we have already added the filter so that we won't do it again the next time the user clicks the Add button.
subgridLookup.customFilterAdded = true;
};

//Attach the function to retrieve the lookup and apply the filter to the Add button's click event. Remember that we
//can only get the lookup after the user has clicked the Add button.
subgridAddButton.addEventListener("click", function() {
setTimeout(getSubgridLookupAndAddFilter, 200);
});
}

*This post is locked for comments

I have the same question (0)

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