Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filter lookup based on the optionset selected

(0) ShareShare
ReportReport
Posted on by 795

Hi All,

My requiremene is i have an optionset and a lookup in header in Case.I want to filter the lookup on the basis of optionset selected. 

Thanks for any help!

*This post is locked for comments

  • Diogo Pedro Profile Picture
    Diogo Pedro 80 on at
    RE: Filter lookup based on the optionset selected

    Hey, new to customization in Dynamics 365. is there any good blog post resource which guides us through this entire process beginning to end.  

  • CRM Beginner  Profile Picture
    CRM Beginner 795 on at
    RE: Filter lookup based on the optionset selected

    yes, i did the same ..

    Xrm.Page.getControl('header_process_new_defectcategory').addPreSearch(addFilter);

    Here, "header_process_new_defectcategory" is the lookup to be filtered

  • ARIFNIIT Profile Picture
    ARIFNIIT 1,391 on at
    RE: Filter lookup based on the optionset selected

    why you are adding presearch event with header_process_new_problemcategory  optionset.?

    Add presearch event for lookup which you want to filter on change of optionset.

  • CRM Beginner  Profile Picture
    CRM Beginner 795 on at
    RE: Filter lookup based on the optionset selected

    Both are optionset

  • ARIFNIIT Profile Picture
    ARIFNIIT 1,391 on at
    RE: Filter lookup based on the optionset selected

    header_process_new_problemcategory is lookup? what is the type of field new_problemcategory?

  • Verified answer
    CRM Beginner  Profile Picture
    CRM Beginner 795 on at
    RE: Filter lookup based on the optionset selected

    Yes Arif , thanks for replying..I solved it. Here is my complete code -:

    function filter_Lookup_Fields()

    {

    if (Xrm.Page.getControl('header_process_new_problemcategory') != null)

    {

    Xrm.Page.getControl('header_process_new_defectcategory').addPreSearch(addFilter);

    }

    }

    function addFilter() {

    var problemcategoryoptionset ;

    var fetchQuery;

    try {

    problemcategoryoptionset = Xrm.Page.getControl('header_process_new_problemcategory').getAttribute().getValue();

    if (Xrm.Page.getControl('header_process_new_problemcategory') != null && Xrm.Page.getControl('header_process_new_problemcategory').getAttribute().getValue() != null) {

    fetchQuery = "<filter type='and'>" +

    "<condition attribute='statecode' operator='eq' value='0' />" +

    "<condition attribute='new_problemcategory' operator='eq' value='" + problemcategoryoptionset  + "' />" +

    "</filter>";

    //add custom filter

    Xrm.Page.getControl('header_process_new_defectcategory').addCustomFilter(fetchQuery);

    }

    }

    catch (e) {

    Xrm.Utility.alertDialog('addFilter Error: ' + (e.description || e.message));

    }

    }

  • ARIFNIIT Profile Picture
    ARIFNIIT 1,391 on at
    RE: Filter lookup based on the optionset selected

    did you solve your error? if not please share your code and tell me complete requirement.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Filter lookup based on the optionset selected

    Hi,

    Could you please share your  the resolution here so that it can help others?

  • Verified answer
    CRM Beginner  Profile Picture
    CRM Beginner 795 on at
    RE: Filter lookup based on the optionset selected

    Thanks All for replies...I resolved it..

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,081 Moderator on at
    RE: Filter lookup based on the optionset selected

    Hi CRM Beginner,

    Post your whole code, if possible so that we are able to find what is wrong?

    Thanks

    Regards,

    AW

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

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,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans