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), DepartmentSmiley Surprisedffice365Users.Manager(Office365Users.MyProfile().Id).Department, DisplayNameSmiley Surprisedffice365Users.Manager(Office365Users.MyProfile().Id).DisplayName, EmailSmiley Surprisedffice365Users.Manager(Office365Users.MyProfile().Id).Mail, JobTitleSmiley Surprisedffice365Users.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
PowerApps Staff carlosag
PowerApps Staff

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.

2 REPLIES 2
PowerApps Staff carlosag
PowerApps Staff

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.

Highlighted
ddas
Level: Powered On

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?