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)

Filtering Lookup

(0) ShareShare
ReportReport
Posted on by

Hi Guyz.. 

          I am a beginner working in crm. I just want to filter look up using addpresearch function. In contact i have two fields state and city. I want to filter City based on the state. I have written the code but i am getting error as

unable to get addPresearch function.

function preFilterLookup() {

Xrm.Page.getControl("new_city").addPreSearch(function () {
addLookupFilter();
});

}

function addLookupFilter() {
//check if the city is not empty



var state = Xrm.Page.getAttribute("new_state").getValue();

//create a filter xml


var filter= "<filter type='and'>" +
"<condition attribute='new_state' operator='eq' value='" + state + "' />" +
"</filter>";
//add filter
Xrm.Page.getControl("new_city").addCustomFilter(filter);


}

*This post is locked for comments

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    Any reason why are you doing this through java script, when this can be done simply setting city lookup property to display city based on state ??

    You can refer: rashans.wordpress.com/.../crm-2011-implementing-dependent-lookups

  • Community Member Profile Picture
    on at

    Ya i know even we can do this by this method also. But just for practice i want to do this way.

  • Suggested answer
    Muhammad Salahuddin Profile Picture
    470 on at

    "<condition attribute='new_state' operator='eq' value='" + state + "' />" +

    "</filter>";

    if "new_state" is lookup field, then.

    Change above line of your code as:

    "<condition attribute='new_state' operator='eq' value='" + state[0].id + "' />" +

    "</filter>";

    also register preFilterLookup() function on form load event.

  • Community Member Profile Picture
    on at

    Actually it is not going inside the function addLookupfilter

  • Mahendar Pal Profile Picture
    45,095 on at

    Just to confirm, you are using CRM 2015 right ??

  • Community Member Profile Picture
    on at

    ya. crm 2015 online.

  • Muhammad Salahuddin Profile Picture
    470 on at

    Please write down the code you have written for below check:

    //check if the city is not empty

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

                 Are you trying to read the control from the Business Flow section??? or from Form area???

    Best Regards

    Shah

  • Mahendar Pal Profile Picture
    45,095 on at

    Sharing screenshots of your field placement over forum, field name could help as well

  • Community Member Profile Picture
    on at

    18787.Capture.PNG      

    In the bottom you can see State and city. These are the lookup fields. Based on the state city should be filtered.

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