Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

filtering a lookup

Posted on by Microsoft Employee

Hey, I want to set the field Region (lookup on new entity) – filtered by Country. if emptied, then empty city

-          Entity Region (has a name field + a lookup on country)

City (lookup on new entity) – filtered by region

Country code à fetched from country automatically

-          Entity: Country (has a name field + area code integer & mandatory  field that only allows 5 characters (ex 00961)

-          Entity Region (has a name field + a lookup on country)

-          Entity City (has a name field and a lookup on country and region)

i'm using the following script but its wrong any help?

function FilterLookup()
{
Xrm.Page.getControl("new_region").addPreSearch(function () {

var region= Xrm.Page.getAttribute("new_region").getValue();

// Get the lookup Object, and extract the value of region
if(region != null)
{
var region = region[0].name;
var city = region[0].text;

// Filter the cities by region
fetchXml = "";

// Apply the filter to the field
Xrm.Page.getControl("new_city").addCustomFilter(fetchXml);
}

});
}

*This post is locked for comments

  • Verified answer
    Saddamk206 Profile Picture
    Saddamk206 777 on at
    RE: filtering a lookup

    Hi please try these.

  • Verified answer
    Inogic Profile Picture
    Inogic 24,094 on at
    RE: filtering a lookup

    You can refer to this http://www.inogic.com/blog/2015/08/apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script/ blog in which we have detailed functioning explained for how filtering is applied with code example. You can check out if you are missing anything.

    Thanks!

     

  • Verified answer
    Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: filtering a lookup

    Hi,

    What happens when your script runs? It looks like this part is wrong:

    fetchXml = "";

    Xrm.Page.getControl("new_city").addCustomFilter(fetchXml);

    because you aren't adding any criteria to the xml, just an empty string. You'll need to add in the actual condition like it's documented here: msdn.microsoft.com/.../gg334266.aspx

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

     Aiden

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans