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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Lookup Filter view based on current user BU

(0) ShareShare
ReportReport
Posted on by 905

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!

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    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

  • EBMRay Profile Picture
    905 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 122

#2
CP04-islander Profile Picture

CP04-islander 57

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 57 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans