Skip to main content

Notifications

Announcements

No record found.

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 879

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
    879 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
    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,001 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans