Skip to main content

Notifications

Dynamics 365 general forum
Answered

How do I filter User Lookup field based on the users being a member of a specific team in a model-driven app?

Posted on by 45

Hello everyone

I have a user Lookup field on my Account entity. I have a model-driven app with the Account main form having this lookup field on it.
Currently, all users in the database are shown. However, I only want to show the users that are part of a specific team (named "Account managers").

pastedimage1670688901669v1.png

We write our scripts in Typescript and add the generated javascript code to my solution using XrmToolbox.
I have already made filters based on properties, but never based on relations.

The Typescript code I'm currently using looks like this:

pastedimage1670689100052v2.png

This code gets executed on the OnLoad event of the form. This code doesn't work.
The relation between a user and team has not been customized. Does anyone know how to filter correctly on team?

This seems like it would be something many developers may have had to do already in the past, which is why I'm asking here.


Thanks in advance.

Junius

  • Junius01 Profile Picture
    Junius01 45 on at
    RE: How do I filter User Lookup field based on the users being a member of a specific team in a model-driven app?

    Thank you for your response. I have taken your idea, and instead made a custom view in the interface (rather than using code to create one), and used that similarly to how you showed me how I could use the user lookup view.

  • Verified answer
    Haig Liu Profile Picture
    Haig Liu Microsoft Employee on at
    RE: How do I filter User Lookup field based on the users being a member of a specific team in a model-driven app?

    Hi Junius01,

    Have you tried out-of-the-box functionality?

    For example, you can customize the default view for the lookup column and then uncheck that the "Allow users to change view":

    pastedimage1670814365501v2.png

    pastedimage1670814448310v3.png

    pastedimage1670814159282v1.png

    You can also create a new lookup view: https://www.forvis.com/article/2022/10/customize-lookup-views-in-microsoft-dynamics-365-crm

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,003 Super User on at
    RE: How do I filter User Lookup field based on the users being a member of a specific team in a model-driven app?

    if you need to filter by team why you filter by businessunitid (that points to Business Unit)? create the filter fetchxml with FetchXML Builder first and check if you are able to retrieve the correct data, after apply the filter to the script

Helpful resources

Quick Links

Upcoming TechTalk: Copilot Capabilities…

Review the Copilot features that are currently available in Dynamics 365 Finance…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,377 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,308 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans