Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Lookup Custom filter error

Posted on by Microsoft Employee

Hi everyone,

I am trying to apply a custom filter to a contact lookup based on a related entity. I am using the addPreSearch and addCustomFilter functions and from what i have seen in various forum it looks like it should be working but whenever i try to test it an error occurs in the console.

There error in the console:

"Uncaught TypeError: $v_5 is not a function
at global.ashx?ver=1149864775:4020
at Mscrm.TurboForm.Control.ViewModel.LookupViewModel.$DW_5 (JsProvider.ashx?bundle=FormControlBundle&ids=1223231347-405283869:21718)
at Mscrm.TurboForm.Control.ViewModel.LookupViewModel.issueLookupSearch (JsProvider.ashx?bundle=FormControlBundle&ids=1223231347-405283869:21723)
at Mscrm.TurboForm.Control.View.LookupEditElement.showSearchResults (JsProvider.ashx?bundle=FormControlBundle&ids=1223231347-405283869:28514)
at Mscrm.TurboForm.Control.View.LookupEditElement.$Il_2 (JsProvider.ashx?bundle=FormControlBundle&ids=1223231347-405283869:29224)
at HTMLInputElement.<anonymous> (MicrosoftAjax.js?ver=1149864775:24)
at HTMLInputElement.b (MicrosoftAjax.js?ver=1149864775:2922)"

The main parts of the code:

function PreFilter() { 
if (Xrm.Page.getAttribute("fieldname").getValue() != null)
{
Xrm.Page.getControl("fieldname").addPreSearch(addLookupFilter());
}
}

...after getting the id's required for the filter:

var fetchXml = "<filter type='and'>";
fetchXml = fetchXml + "<condition attribute='contactid' operator='in'>";
for (var j = 0; j < tenants.length; j++) {
     fetchXml = fetchXml + "<value>{" + tenants[j]["id"].toUpperCase() + "}</value>";
}
fetchXml = fetchXml + "</condition>";
fetchXml = fetchXml + "</filter>";
Xrm.Page.getControl("field").addCustomFilter(fetchXml, "contact");

I have used alerts in the script to see where it gets to and what the fetchXml looks like and it all seemed okay to me, this is an example of what its returned:

<filter type='and'>
<condition attribute='contactid' operator='in'>
<value>{1300A5B9-83FD-E311-80C1-0050568F0035}</value>
<value>{8500A5B9-83FD-E311-80C1-0050568F0035}</value>
</condition>
</filter>

If anyone could tell me why i am getting this error, it would be greatly appreciated.

*This post is locked for comments

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Lookup Custom filter error

    Can you please post full code?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Lookup Custom filter error

    Hi,

    Thanks for your reply. Removing those brackets stopped me getting the error but it's still not applying the filter. Am i going wrong anywhere else?

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Lookup Custom filter error

    Hello,

    Try to replace

    Xrm.Page.getControl("fieldname").addPreSearch(addLookupFilter());

    with

    Xrm.Page.getControl("fieldname").addPreSearch(addLookupFilter);

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans