Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Issue with dynamic filtration of Lookup field using javascript

Posted on by Microsoft Employee

Hi,

I have been working on CRM 2013 on-premise. I am trying to apply dynamic filtration on a lookup field based on the value chosen in 3 other lookup fields.

8765.CRM.png

All the fields are lookup fields and I am using a javascript to filter value of Test Sell Rate based on value entered in all the above fields. Test Sell rate entity has all the above entities present as lookup fields in it. I am applying my javascript on change event on field Test Level. I am using the following code:

src="ajax.googleapis.com/.../jquery.min.js"

function preFilterLookup() {
Xrm.Page.getControl("testsellrate").addPreSearch(function ()
{
addLookupFilter();

});
}
function addLookupFilter()
{
var rolecategory = Xrm.Page.getAttribute("testrolecategory").getValue();
var role = Xrm.Page.getAttribute("testrole").getValue();
var pricelist = Xrm.Page.getAttribute("testpricelist").getValue();
var level = Xrm.Page.getAttribute("testlevel").getValue();

if (level != null)
{
fetchXml = "<filter type='and'><condition attribute='testrolecategory' operator='eq' value='" + rolecategory + "' /><condition attribute='testrole' operator='eq' value='" + role + "' /><condition attribute='testlevel' operator='eq' value='" + level + "' /><condition attribute='testpricelist' operator='eq' value='" + pricelist + "' /></filter>";
Xrm.Page.getControl("testsellrate").addCustomFilter(fetchXml);
}
           

I am getting following error:

Microsoft Dynamics CRM Error Report Contents

<CrmScriptErrorReport>
<ReportVersion>1.0</ReportVersion>
<ScriptErrorDetails>
<Message>Unable to get property 'addPreSearch' of undefined or null reference</Message>
<Line>4</Line>
<URL>/%7B636623675690000145%7D/WebResources/new_filteredlookup</URL>
<PageURL>/main.aspx?etc=10018&extraqs=%3f_CreateFromId%3d%257bE4DD5965-2C23-E811-811F-003048D10ACE%257d%26_CreateFromType%3d3%26_gridType%3d10018%26etc%3d10018%26id%3d%257b8DCF0143-5348-E811-8121-003048D10ACE%257d%26rskey%3d%257bB15E6CA9-5B9E-4C74-881E-3577FE1F8BA1%257d&pagemode=iframe&pagetype=entityrecord&rskey=%7bB15E6CA9-5B9E-4C74-881E-3577FE1F8BA1%7d</PageURL>
<Function>anonymousr:Unabletogetproperty'addPreSearch'ofundefinedornullreference</Function>
<CallStack>
<Function>anonymousr:Unabletogetproperty'addPreSearch'ofundefinedornullreference</Function>
</CallStack>
</ScriptErrorDetails>
<ClientInformation>
<BrowserUserAgent>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134</BrowserUserAgent>
<BrowserLanguage>undefined</BrowserLanguage>
<SystemLanguage>undefined</SystemLanguage>
<UserLanguage>undefined</UserLanguage>
<ScreenResolution>1707x960</ScreenResolution>
<ClientName>Web</ClientName>
<ClientTime>2018-05-21T23:11:29</ClientTime>
</ClientInformation>
</CrmScriptErrorReport>

Is anyone else facing an issue like this?

*This post is locked for comments

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 on at
    RE: Issue with dynamic filtration of Lookup field using javascript

    Hi Lucky,

    Please check this link for adding Filter to a lookup,

    www.inogic.com/.../apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script

    Best Regards,

    Shahbaaz

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Issue with dynamic filtration of Lookup field using javascript

    Hi ,

    Make sure your lookup attribute name is correct with publisher name . Try to add null check  -

    function preFilterLookup() {
        if (Xrm.Page.getControl("testsellrate") != null && Xrm.Page.getControl("testsellrate") !=undefined) {
    
            Xrm.Page.getControl("testsellrate").addPreSearch(function () {
                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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans