Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how to change lookup field's view based on form data ?

(0) ShareShare
ReportReport
Posted on by 1,431

Based on form data (a check box) look up field on form is required to returned different contacts. If Employer check box on form is checked look up field view should return only those contacts (filtered) who belongs to current form's employer other wise look up should return all contacts.

Any idea how to achieve it ? Please guide if multiple ways are available to do that. Will highly appreciate if a relevant link is shared.

Thanks

*This post is locked for comments

  • Verified answer
    Haansi Profile Picture
    Haansi 1,431 on at
    RE: how to change lookup field's view based on form data ?

    I couldn't test suggested answers since later requirements were changed but thanks for replying me.

  • Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: how to change lookup field's view based on form data ?

    It this resolves your problem, spend few minutes to mark answers as suggested. Thank you.

  • Verified answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: how to change lookup field's view based on form data ?

    Hi Yawer,

    You need to create the custom lookup field, Kindly follow the below url:

    www.c-sharpcorner.com/.../how-to-create-custom-lookup-view-in-crm2

    Thanks

    Hemant Sahu

  • Verified answer
    Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: how to change lookup field's view based on form data ?

    Hi Yawer,

    This is possible. You will have to use addPreSearch method or addCustomFilter methods given in SDK. Below link is the reference point for the same.

    https://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_lookupControlMethods

    Below are the high level steps:

    1. Register a JavaScript method on form's on load event.

    2. In this method, register addPreSearch method for your lookup control. This will register a method in which you can change the filters dynamically at runtime. addPreSearch method will be called everytime user searches for lookup record in lookup field.

    3. To set filter criteria, you can use global variable. Below is high level skeleton of the code:

    var accountName = "xyz";
    
    function onLoad()//register this event on your form's load event.
    {
           Xrm.Page.getControl("AccountLookupField").addPreSearch(filterAccounts);
    }
    
    function filterAccounts()
    {
          var customerAccountFilter = "<filter type='and'><condition attribute='name' operator='eq' value='"+accountName+"'/></filter>";
          Xrm.Page.getControl("parentaccountid").addCustomFilter(customerAccountFilter, "account");
    }
    
    function setRunTimeFilterValue()
    {
          if(Employer checkbox checked)
          {
                accountName = "hello";//here your logic of employer will be placed
          }
    }


    Kindly mark suggested answer checkbox if this resolves your query.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans