cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Occasional Errors while using Office365Users function

In my app, quite often I use the Office365Users function to get information about the user or his/her manager. I noticed that sometimes those functions produce errors while sometimes they work perfectly.

One of the error I get is this:

The service returned an error: Office365Users!Manager: The method ‘Manager’ has an invalid value for parameter ‘userId’

Here is the code where the error occurs:

{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",            
Claims:Concatenate("i:0#.f|membership|",Office365Users.Manager(Office365Users.MyProfile().Id).Mail), Department:Office365Users.Manager(Office365Users.MyProfile().Id).Department, DisplayName:Office365Users.Manager(Office365Users.MyProfile().Id).DisplayName, Email:Office365Users.Manager(Office365Users.MyProfile().Id).Mail, JobTitle:Office365Users.Manager(Office365Users.MyProfile().Id).JobTitle, Picture:"" }

Also quite often I get this error:

The service returned an error: Office365!MyProfile: The server returned an HTTP error with code 0.

Sometimes I get no errors and everything works fine. So, when I get the second error (HTTP) what could be causing it? Because the way I understand it, the Office365MyProfile() function gets an error while trying to retrieve the info on the users, that’s why it throws HTTP error. Of course because MyProfile() function failed so will the Manager as it uses MyProfile() as an input, that’s why I get the first error.

I am thinking could it be our system not sending the info over as I keep requesting it from the server too often? How would I even check that? Is there a way to write the fuction differently to get more info from the errors and why the function is failing?

 

Also FYI, this function is in a add record form card for a field which is in SharePoint list as Person or Group.

 

Thanks for any insight!

 

EDIT: I forgot an important detail. Almost 80% of the time I get NO errors while I do development and launch the app in the PowerApps web development studio. But the app is also embeded in a SharePoint page. And when I test the app on the SharePoint page I get the error 90% of the time. So Strange

1 ACCEPTED SOLUTION

Accepted Solutions
carlosag
Power Apps
Power Apps

I would strongly recommend to move to use a Context variable to store the Id of the user so that it does not call the connector "n" number of times for MyProfile and "m" number of times to Manager(), and avoid the performance hit and the network risk that each call has.

 

So for that, I would add on the OnVisible of that screen add:

UpdateContext({UserProfile: Office365Users.MyProfile() }); 
UpdateContext ({Manager: Office365Users.Manager(UserProfile.Id)})

 

Then your code would look like:

{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",            
             Claims:Concatenate("i:0#.f|membership|",Manager.Mail),
             Department: Manager.Department,
             DisplayName: Manager.DisplayName,
             Email: Manager.Mail,
             JobTitle: Manager.JobTitle,
             Picture:""
}

This should be dramatically faster and safer.

View solution in original post

2 REPLIES 2
carlosag
Power Apps
Power Apps

I would strongly recommend to move to use a Context variable to store the Id of the user so that it does not call the connector "n" number of times for MyProfile and "m" number of times to Manager(), and avoid the performance hit and the network risk that each call has.

 

So for that, I would add on the OnVisible of that screen add:

UpdateContext({UserProfile: Office365Users.MyProfile() }); 
UpdateContext ({Manager: Office365Users.Manager(UserProfile.Id)})

 

Then your code would look like:

{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",            
             Claims:Concatenate("i:0#.f|membership|",Manager.Mail),
             Department: Manager.Department,
             DisplayName: Manager.DisplayName,
             Email: Manager.Mail,
             JobTitle: Manager.JobTitle,
             Picture:""
}

This should be dramatically faster and safer.

View solution in original post

You said the code in the first box goes in the OnVisible part of the screen but where does the code in the second box go? 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,787)