web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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

I have the same question (0)
  • Suggested answer
    Iswarya Profile Picture
    1,347 on at

    Hi,

    see this

    www.aayushsingh.in/.../how-to-add-custom-filter-lookup-field.html

  • Suggested answer
    ARIFNIIT Profile Picture
    1,391 on at

    Write JavaScript on Change event of optionset and apply fetchxml filters for lookup,

  • CRM Beginner Profile Picture
    795 on at

    Hi Arif,

    I am getting this error : "An exception System.FormatException was thrown while trying to convert input value 'Package' to attribute 'new_twg_defectcategory.new_twg_problemcategory'. Expected type of attribute value: System.Int32. Exception raised: Input string was not in a correct format." Can you tell me why its coming ?

  • Suggested answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi CRM Beginner,

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

    Thanks

    Regards,

    AW

  • Verified answer
    CRM Beginner Profile Picture
    795 on at

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

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

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

  • ARIFNIIT Profile Picture
    1,391 on at

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

  • Verified answer
    CRM Beginner Profile Picture
    795 on at

    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
    1,391 on at

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

  • CRM Beginner Profile Picture
    795 on at

    Both are optionset

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans