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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filtered Lookup from another Lookup

(0) ShareShare
ReportReport
Posted on by

Well...well...trying to do a filtered lookup AFTER another lookup is chosen.  Both lookups have another common lookup amongst each other to Subject.

I can't seem to wrap my mind around it.

The business logic is like this:

-->Create New Custom Entity

-->Choose a Case

-->Filter Custom Type to Subject chosen in Case

First...can this be done via plugin or is it a JS and/or something else only?

And...GO!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mamatha Swamy Profile Picture
    5,426 on at

    You cannot do this in a plugin if you want the user to choose the value of the filtered lookup. You'll need JScript for this.

    Refer

    community.dynamics.com/.../crm-2013-javascript-lookup-filtering-using-addcustomfilter

    missdynamicscrm.blogspot.com/.../crm-2013-using-addcustomfilter-to-get-filtered-lookup-field-based-on-linked-entity.html

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Check theses links might be helpful

    [View:http://missdynamicscrm.blogspot.com/2014/11/filter-lookup-field-by-related-subgrid-crm-2011-2013.html?_sm_au_=iVVVM0Mr8Hv5F0j0:0:0]

    [View:http://nalashaa.com/filtered-lookup-dynamics-crm-2013/:0:0]

    [View:https://community.dynamics.com/crm/f/117/t/154898:0:0]

    [View:http://crmadminassist.com/microsoft-dynamics-crm-dependent-lookups/:0:0]

  • Community Member Profile Picture
    on at

    Some great links and thank you!  But most I have found and all filter a lookup from another "normal" field but not from a lookup field that acts like an entity reference.

    On top of that it's an entity reference that has key information that needs to be filtered on.

  • Aileen Gusni Profile Picture
    44,524 on at

    Paul,

    If it is just a common lookup field than you should be able achieve with this:

    crmadminassist.com/microsoft-dynamics-crm-dependent-lookups

    garethtuckercrm.com/.../filtered-lookup-approaches-in-crm-2011

    But since you are talking about Subject, it can be different.

    Btw, Custom Type and Subject, is not related right?

    You mean it is OOB Subject?

    Thanks.

  • Suggested answer
    mscrmba Profile Picture
    on at

    Could you just bring the Subject field through from Case onto this record  as a hidden field:  when the Case record is selected/updated (O-Data query) or any time the associated Case's subject is updated (would require a plug-in) and use that drive the child lookup instead?  Is there any particular reason why it needs to reference back to the Case's subject dynamically?

    Perhaps I'm missing the issue here - but here is the scenario I understand you are considering:

    Field Parent - lookup field with options A, B, C

    Field Child, Lookup with options A1, A2, A3, AB1, B2, B3, C1

    1.  Do you have the parent lookup as a lookup field on the child lookup entity?  You'd add it.

    2. Create multiple records in the child lookup - one for each parent level item that makes sense for it.

    So for the scenario above, in the Child lookup table at a record level (each line representing a separate record) you have:

    A1, Parent=A, Subject = whatever you want

    A2, Parent=A, Subject = whatever you want

    A3, Parent=A, Subject = whatever you want

    AB1, Parent=A, Subject = whatever you want

    AB1, Parent=B, Subject = whatever you want

    B2, Parent = B, Subject = whatever you want

    B3, Parent = B, Subject = whatever you want

    C1, Parent = C, Subject = whatever you want

    3. Then put the OOTB filtered view on the child record, filtering by the Parent field (but maybe this also needs to be by the subject field?).

    So if A is selected as the parent you get to select from the following for the Child record:

    A1, Parent=A, Subject = whatever you want

    A2, Parent=A, Subject = whatever you want

    A3, Parent=A, Subject = whatever you want

    AB1, Parent=A, Subject = whatever you want

    If B is selected as the parent you get to select from the following for the Child record:

    AB1, Parent=B, Subject = whatever you want

    B2, Parent = B, Subject = whatever you want

    B3, Parent = B, Subject = whatever you want

    If C is selected as the parent you get to select from the following for the Child record:

    C1, Parent = C, Subject = whatever you want

    You child lookup table is a big table - a row for every valid cross match between subject, parent and child scenario.

    Can you give us a bit more of the business scenario?

  • Community Member Profile Picture
    on at

    "Could you just bring the Subject field through from Case onto this record  (as a hidden field when the Case record is selected/updated (O-Data query) or any time the associated Case's subject is updated (would require a plug-in) and use that drive the child lookup instead?  Is there any particular reason why it needs to reference back to the Case's subject dynamically?"

    I thought about that but what happens when they change the case? You would still need to update the subject (hidden) via plugin and so the second lookup relation wouldn't be correct.

  • mscrmba Profile Picture
    on at

    The subject needs to stay in sync between parent & child...

    1.  Make the subject mandatory and then read only after initial population at the parent level (and hidden at the child level).  (If the business could live with that...)

    2. Or you could have a custom code on the Case record for 'update Subject'.  That updates any associated custom record's Subjects.  Then (possibly a workflow) that for each one it updates t change the child lookup value to populate it with the one where Subject = new Subject & Parent = Parent.  

  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at

    What I understood your problem as

    You have Entity "Parent" which has two lookups say LookupA & LookupB, A & B has common entity Subject lookup LookupS.

    Now when in parent entity Lookup A is selected, then you want to show only those records in LookupB which has same LookupS.
    in another words.. when first lookup is selected you want to show only records in second lookup which has same subject for first lookup record.

    In this case you can do using JavaScript add following code on First lookup on change

    function preFilterStudentLookup() {
    debugger;
    Xrm.Page.getControl("new_studentid").addPreSearch(function () {
    addLookupStudentFilter();

    });
    }
    function addLookupStudentFilter() {
    debugger;
    var parentChild = Xrm.Page.getAttribute("new_primarychildid").getValue();
    var ctrl = Xrm.Page.getControl('ChildQuickView_ChildQuickView_edm_test_new_subjectid');
    var ParentChildSubject = ctrl.getAttribute().getValue();
    var fetchXml = '<filter type="and"><condition attribute="new_subjectid" value="' + ParentChildSubject[0].id + '" operator="eq"/></filter>';
    Xrm.Page.getControl("new_studentid").addCustomFilter(fetchXml);
    }

    to use this code you need to create one quick view form for First lookup entity which will contain Subject Lookup. add this quick view form on your parent entity.. where two lookups you want to filter.
    And change following ids with respective


    new_studentid ==> Your Second lookup which want to filter based on First.

    new_primarychildid ==> Your First lookup

    ChildQuickView_ChildQuickView_edm_test_new_subjectid ==> QuickFormname_QuickFormname_EntityName_AttributeName
    (for more info on accessing quick view form attribute.. 

     [View:http://mahadeomatre.blogspot.com/2015/03/access-quick-view-form-values-in.html?_sm_au_=iVV7ZWtjTjq5R0PF:550:0]


    Now when first lookup is selected and has subject say Product.. then in second lookup, only those records will be shown which has Subject product.

    hope this will help.. 

  • Community Member Profile Picture
    on at

    I must be doing something wrong...

    Basically Custom entity has a Case Lookup which should limit the Type Lookup entity.  Case has Subject entity and Type has Subject entity.

    So how to limit Type entity based upon the Case entity and the Subject entity it contains.

  • Mahadeo Matre Profile Picture
    17,021 on at

    Where did you put your code?you have to put your code first lookup on change and try debugging with any browser..it will give you idea where you are doing wrong

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans