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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filter Owning Business...
Power Apps
Unanswered

Filter Owning Business Unit (OBU) Lookup

(0) ShareShare
ReportReport
Posted on by

Hi all, 

I have allowed the  record ownership across business units feature in the environment and add the "Owning Business Unit" (OBU) lookup in the header of the form. I have added a team in the target BU which has several security roles to let the user choose it as owning BU for the record. 

The problem is that the OBU  lookup shows all the business units in the system and not just the related business units, which will be a big problem. I would like to show only the business unit that the user belongs to and the target BU which the user is a member of a team in it.

Is there a way to do it ?

Is there a way to get all the teams that the user is involved in?

 

 

I have the same question (0)
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Hello,

    How do you define "related business unit" criteria?

  • Alloylo Profile Picture
    on at

    Hi, 

    The related BU is the business unit that the user is already in and the BU that has a team in which the user is added to.

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Hello,

    I was typing the code just in VSCode + Github Copilot so it might be not 100% working but I hope you will get an idea. Attach the following code to OnLoad event of the form:

    async function onLoad(executionContext) {
     var formContext = executionContext.getFormContext();
    
     var teamFetchXml = [
     '<fetch>',
     '<entity name="team">',
     '<attribute name="businessunitid" />',
     '<link-entity name="teammembership" from="teamid" to="teamid" intersect="true">',
     '<filter>',
     '<condition attribute="systemuserid" operator="eq-userid" />',
     '</filter>',
     '</link-entity>',
     '</entity>',
     '</fetch>'
     ].join("");
    
     var teamResult = await Xrm.WebApi.retrieveMultipleRecords("team", "?fetchXml=" + teamFetchXml);
    
     var userBusinessUnits = teamResult.entities.map(function (team) {
     return team["_businessunitid_value"];
     });
    
     var userId = Xrm.Utility.getGlobalContext().userSettings.userId;
    
     var businessUnit = await Xrm.WebApi.retrieveRecord("systemuser", userId, "?$select=_businessunitid_value");
     userBusinessUnits.push(businessUnit["_businessunitid_value"]);
    
     var businessUnitFilter = [
     '<filter>',
     '<condition attribute="businessunitid" operator="in">',
     userBusinessUnits.map(function (bu) {
     return "<value>" + bu + "</value>";
     }).join(""),
     '</condition>',
     '</filter>'
     ].join("");
    
     formContext.getControl("header_owningbusinessunitid").addPreSearch(function () {
     formContext.getControl("header_owningbusinessunitid").addCustomFilter(businessUnitFilter, "businessunit");
     });
    }
  • Alloylo Profile Picture
    on at

    Thanks for your help, I will try it 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 326 Most Valuable Professional

#2
11manish Profile Picture

11manish 168

#3
sannavajjala87 Profile Picture

sannavajjala87 75 Super User 2026 Season 1

Last 30 days Overall leaderboard