Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Filtered Lookup - Dynamics Portal

(0) ShareShare
ReportReport
Posted on by 146

Hi, 

I have seen information about filtering a lookup in Dynamics Portal but doesn't seem like anything is working for me. I have three custom entities

Programmes (1-N) Programme-courses (N-1) Courses

I have a subgrid on Programmes with associated Programme-courses records.
I have added metadata so that you can create a new record on this subgrid.

When you click Create it opens a new Programme-courses record, which has a lookup to entity Courses. I need to be able to filter the lookup for Courses based on accounts which are associated to Courses. 
I have the account lookup on Programme-courses and it is also the same account which is associated to the current user (the logged in user is the primary contact for this account)
I have created entity permissions on the Programme-course record to with account scope, and entity permissions for the course as a child permission.

Any help getting the lookup filtered as desired?

Thanks!

*This post is locked for comments

  • Davina Sungum Profile Picture
    Davina Sungum 146 on at
    RE: Filtered Lookup - Dynamics Portal

    Hi Matt,

    Thanks so much for you explanation and link, I will give this a go when required :)

    I was hoping that this could be achieved using the standard custom JS section on the web form step using add PreSearch on the lookup for example in CRM:

    Xrm.Page.getControl("mycontactfield").addPreSearch(filterContactNameLookup(customerID[0].id));

    instead for portals it might be something like:

    $(#"mycontactfield").addPreSearch(filterContactNameLookup(customerID[0].id));

    Would that not work?

    Thanks,

    Davina

  • Suggested answer
    - Matt Bayes - Profile Picture
    - Matt Bayes - 890 on at
    RE: Filtered Lookup - Dynamics Portal

    Davina,

    I'm glad that worked for you!

    As for the FetchXML, you can follow the guide here:

    https://colinvermander.com/2017/04/17/dynamics-365-portals-use-liquid-to-return-json-or-xml/

    Essentially, you create a Web Template with the FetchXML block you want and make sure the MIME type is application/json. In the Web Template you build out the JSON object with the returned results. You can accept parameters via the URL and use those to filter the records returned.

    After the Web Template, you create a blank page and page template using that created Web Template. Essentially what we have done is built a custom API URL that we can use a GET on to retrieve the records.

    After that's setup, using an AJAX GET call, pointing to the URL of the page created and passing in query string parameters, you can retrieve the records in a JSON object which you can parse out and work with.

    From there you can then write other Jquery to do any form manipulations as needed.

    A use case for me is a user selects a Product on the portal, and as soon as they select it, it retrieves the price of the product and populates into fields on a Web Template. Although a Quick View could accomplish the same thing, we formatted the Product lookup as a drop-down which negated the Quick View functionality on the portal.

    Let me know if you have any other questions!

    Thanks!

    Matt Bayes

  • Davina Sungum Profile Picture
    Davina Sungum 146 on at
    RE: Filtered Lookup - Dynamics Portal

    Hi Matt,

    Thanks for your reply, I just saw it after I wrote my own reply!

    I did get it working with entity permissions but then I tried the standard lookup filtering which now works as I added the account lookup to the programme-course entity.

    Any chance you have any example with FetchXML, I have other requirements which I believe I'll need it for and and wasnt sure if you can use a similar methods like you would in CRM but with JQuery $ instead of XRM.Page for example.

    Thank you!

  • Davina Sungum Profile Picture
    Davina Sungum 146 on at
    RE: Filtered Lookup - Dynamics Portal

    I have it working! Entity permissions on the course record with Account scope is all I needed. I removed the Parent permission.

  • Verified answer
    - Matt Bayes - Profile Picture
    - Matt Bayes - 890 on at
    RE: Filtered Lookup - Dynamics Portal

    Hi Davina,

    The portal inherits the functionality from CRM in regards to filtered lookups. To have this work for the portal:

    1. Open CRM and navigate to the specific form you are using on the portal inside a solution.
    2. Open up the form for the Programme-Courses entity and find the Course field.
    3. Edit this field and scroll down on the first tab. You should see a "Related Records Filtering" section.
    4. Setup this section to only show records where the Account on the specific Course equals the Account on the Programme-Course.

    Here is an example of one I have setup for Event (1:N) Event Pass based on the Event on an Opportunity:

    FilteredLookup.PNG

    An alternative is to also write Javascript on the portal with a FetchXml web template that will return you a subset of records based on parameters you send in, and then populate accordingly. This shouldn't be needed but is an option if you are comfortable with client-side code on the portal.

    Thanks!

    Matt Bayes

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…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans