cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Power Apps
Power Apps

Re: Occasional Errors while using Office365Users function

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
Highlighted
Power Apps
Power Apps

Re: Occasional Errors while using Office365Users function

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

Highlighted
Helper II
Helper II

Re: Occasional Errors while using Office365Users function

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
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (4,457)