Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Lookup Filter view based on current user BU

Posted on by 873

Hello everyone,

In the accounts entity, we have the Territory lookup field. A business unit can cover multiple territories for example (BU A covers: TerA, TerB, BU B covers: TerC, TerD) I want to achieve the below:

  • Based on the current user signed-in belonging BU, when the user selects the Territory field it should show only the view that is associated with his BU.

So User A that belongs to BU A cannot see the territories of User B that belong to BU B or change the view.

Terro.PNG

Is it possible to achieve the above scenario? If so, what is the best way of doing it? Can please someone provide an example?

Any help is highly appreciated.

Thank you!

  • EBMRay Profile Picture
    EBMRay 873 on at
    RE: Lookup Filter view based on current user BU

    Hi   ,

    Thank you for your reply and for providing the steps needed.

    1. I have created a custom field which is Business Unit that is lookup on the BU table.
    NewTerr.PNG
    2. As you mentioned, I have to retrieve the current user BU. What is the Web API that should be called to retrieve the BU id of the user by using userSettings?

    3. After I have the data from point no.2 should I call the Xrm.WebApi retrievemultiplerecords against the territory entity to filter the BU of the user against the territory field that I created?

    4. On which event the JS code should be called on form level or field level?

    5. Could you please provide a simple sample example? I will also start to prepare the code and post it here and would highly appreciate it if you can assist.

    Awaiting your response.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Lookup Filter view based on current user BU

    Hi EBMRay, 

    Unfortunately, you can't filter it through add condition in the lookup view.

    If you want to do this, you need use js code and web api.

    1. Get the current userId.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utility/getglobalcontext/usersettings#userid 

    2. Retrieve current user with current  userId to get the BU id(lookup field).

    pastedimage1635923755121v1.png

    3. Get all users belong to current user's BU by web api with BU id.

    4. Use these users as filter to addCustomFilter() function:

    addCustomFilter (Client API reference) in model-driven apps - Power Apps | Microsoft Docs

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans