Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Related records filtering with custom fields crm 2013

Posted on by Microsoft Employee

I have the following:

* CASE entity with two custom fields:

1) Class option set Field

2) Account Lookup Field

Based on the selection in the option set field (4 options) I want to filter the accounts displayed in the account lookup field. i.e. I want only accounts with the selected Class.

I have a custom option set field on the account form that holds the Class of each account, however, the user needs to specify the Class again via the option set on the CASE. Based on this field I want to only show accounts on the lookup that fall into this category.

Am I missing relationship or something?? I have tried some preFilterLookup code - but it isnt working for me.

Help appreciated.

*This post is locked for comments

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Related records filtering with custom fields crm 2013

    If values (integer codes) are the same your code should work fine. If something goes wrong way you will have to troubleshoot your code - blogs.msdn.microsoft.com/.../debugging-custom-javascript-code-in-crm-using-browser-developer-tools

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Related records filtering with custom fields crm 2013

    Thanks for the response.

    They are two different option set FIELDS with the same values...one on the account form and one on the case form.

    NOTE there is no relationship between them - the user manually selects  both...

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Related records filtering with custom fields crm 2013

    If you want to add filter to account dataset returned - account should have new_class optionset with the same values as new_class optionset on case entity.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Related records filtering with custom fields crm 2013
    function preFilterLookup() {    
    	
    	Xrm.Page.getControl("new_practicepractitioner").addPreSearch(function () {
         addLookupFilter();
       });
    }
    function addLookupFilter() {
        var email = Xrm.Page.getAttribute("new_class").getValue(); // the class field in the case form
        if (email != null) {
    	
            fetchXml = "<filter type='and'><condition attribute='new_class' operator='eq' value='" + email + "' /></filter>";            
    		Xrm.Page.getControl("new_practicepractitioner").addCustomFilter(fetchXml);
        }
    }

    new_practicepractitioner = the lookup field to account ON THE CASE form

    new_class = the option set field on the CASE form

    I was not sure if the condition attribute needed to be the class field on the ACCOUNT form???

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Related records filtering with custom fields crm 2013

    Hello,

    Can you please provide code you tried? That approach works fine for me.

  • Joe Gill Profile Picture
    Joe Gill on at
    RE: Related records filtering with custom fields crm 2013

    Hi,

    The preFilter code should work have a look at http://www.magnetismsolutions.com/blog/nathaneccles/2013/09/30/crm-2013-javascript-lookup-filtering-using-addcustomfilter

    Have you tried debugging your code?

    Joe

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans