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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Custom filter using Option Set

(0) ShareShare
ReportReport
Posted on by

I have a lookup field on my form and I want to use a status field (custom) to use as the custom filter.  My code looks like this:

function preFilterLookupRMA() {

Xrm.Page.getControl("lena_dlp_sn").addPreSearch(function () {addLookupFilterRMA();});

}

function addLookupFilterRMA() {

fetchXml = "<filter type='and'><condition attribute='lena_dlp_statusid' operator='eq' value='935240004' /></filter>";

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

}

The function preFilterLookupRMA is called onLoad.  My issue is the "value" parameter in the fetchXML.  The value entered is the one assigned to that Option in the Option Set that I created, but when this code is run it returns 0 records.  I know that there are records that match my intended criteria.  The status field is for the lookup record, not the record the form is on.

I have also tried adding the Option text, but it gives an error since this field is looking for a numeric value.

How do I get the proper value of the Option Set so that this filter only gives me the records I want?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi Rengeek,

    This filter:

    "<filter type='and'><condition attribute='lena_dlp_statusid' operator='eq' value='935240004' /></filter>";

    Is that you are trying to make as dynamic or it is always static?

    If it is static, you can have it done without custom code.

    Create a View for the lookup field entity, for example:

    lena_dlp_sn

    Edit your filter criteria of the view.

    Filter only where status = the value you wanted.

    Save it.

    Go to Form Editor, double click the lookup field for detail properties, for example:

    In the additional properties, choose your created view before as the Default View and Turn off the view selector so that the user will not be able to change it.

    Hope this helps!

    Thanks.

  • Aileen Gusni Profile Picture
    44,524 on at

    Rengeek,

    Basically, it seems okay on your code, check this:

    mscrmmindfire.wordpress.com/.../filtering-lookup-depending-upon-the-optionset-value

    But, I hope that you can achieve that from the UI Customization!

    Thanks.

  • Community Member Profile Picture
    on at

    Thanks Aileen - that takes care of regular "lookup" fields, but what about subgrids?  If I set the "View", it filters the subgrid, but not the search.  

  • Aileen Gusni Profile Picture
    44,524 on at

    Don,

    I have tried, after I search it still filters based on the set view.

    Or Maybe I am confused with what you are referring to.

    Thanks.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans