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 / How to handle errors f...
Power Apps
Answered

How to handle errors for Office365Users.Manager when no Manger in AD

(0) ShareShare
ReportReport
Posted on by 1,207

I have an app that gets the user's manager for approvals. If no manager is returned the user can search users and set a manager manually. 

 

First I get the employee's AD record using Office365.SearchUserV2

 

// set default employee
Set(
 varDefaultUser,
 First(
 Office365Users.SearchUserV2(
 {
 searchTerm: Trim(User().Email),
 top: 1
 }
 ).value
 )
);

 

 

Then I use the user's Id to get the Manager

 

// set manager
If(
 !IsBlank(varDefaultUser.Id),
 Set(
 varDefaultManager,
 Office365Users.Manager(varDefaultUser.Id)
 )
);

 

 

If the user doesn't have a manager set in AD I get errors. I've switched on formula level error management to suppress the Power Apps errors to the user, but still getting errors using the app with a user without a manager.

 

This function would be better if it returned false when the user has no manager instead throwing errors. Is there a way I can test for error and take an alternate action and avoid displaying errors to the user? If the user doesn't have a manager i.e. varDefaultManager is blank then I display a people picker for them to select their own approver.

 

Categories:
  • Verified answer
    Fredrik_A Profile Picture
    3,644 Super User 2026 Season 2 on at

    I had the same issue, i used an IfError if i recall correctly:

     

    https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-iferror

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 352 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 323

#3
Mohsin Ali Profile Picture

Mohsin Ali 226

Last 30 days Overall leaderboard