Hi , I have created one app that will patch Office 365 users to share point lists the thing is it patches the currency user manager and how to patch each emp in the list manager
the code I have user is below:
still no Line manager name but if I use Office365Users.MyProfileV2().id it will show as you saw up
and if you try to patch your own record with your manager into the list?
With({FirstUser:
LookUp(
Office365Users.SearchUser({searchTerm:User().Email}),
AccountEnabled = true
)},
With({UserManager:
Office365Users.ManagerV2(FirstUser.Id)
},
Patch(
'Employee information list',
// If the user does not exist, create a new item
Defaults('Employee information list'),
{
Display_name: FirstUser.DisplayName,
Phone_number: FirstUser.MobilePhone,
First_name: FirstUser.GivenName,
Department_Name: FirstUser.Department,
'designation ': FirstUser.JobTitle,
Email: FirstUser.Mail,
'Line Manager1': {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: "i:0#.f|membership|" & UserManager.userPrincipalName,
Department: "",
DisplayName: UserManager.displayName,
Email: UserManager.mail,
JobTitle: "",
Picture: ""
}
}
)
)
)
The result in my manager email
Did you also verify mail and displayName?
If you add a label and set its Text to:
With({FirstUser:
LookUp(
Office365Users.SearchUser({searchTerm:User().Email}),
AccountEnabled = true
)},
With({UserManager:
Office365Users.ManagerV2(FirstUser.Id)
},
UserManager.userPrincipalName
)
)
You should be able to see your manager's email, please share the result
Hi, I used lowercase and still it will not patch each employee manager name
HI @MarwaAlhajri ,
He is talking about this part, this is my code
Claims: "i:0#.f|membership|" & UserManager.UserPrincipalName,
and this is @royg corrected code
Claims: "i:0#.f|membership|" & UserManager.userPrincipalName,
He is talking about UserManager property userPrincipalName had a Upercase in my code.
Sorry to ask but what are UserManager properties should start with lowercase , and used the Concat code it only shows the user info without line manager so weird
Hi @MarwaAlhajri,
@Giraldoj's code look OK to me. I think the UserManager properties should start with lowercase:
'Line Manager1': {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: "i:0#.f|membership|" & UserManager.userPrincipalName,
Department: "",
DisplayName: UserManager.displayName,
Email: UserManager.mail,
JobTitle: "",
Picture: ""
}
In addition, I'd replace the If/Else with Coalesce() that applies the first non-blank object (either the existing item or the default new item), thus reducing the code for simplicity and maintenance. So, the patch should resemble:
With({
ExistingItem: LookUp(
'Employee information list',
Email = Mail
),
UserManager: Office365Users.ManagerV2(Id)
},
Patch(
'Employee information list',
// If the user does not exist, create a new item
Coalesce(ExistingItem, Defaults('Employee information list')),
{
Display_name: DisplayName,
Phone_number: MobilePhone,
First_name: GivenName,
Department_Name: Department,
'designation ': JobTitle,
Email: Mail,
'Line Manager1': {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: "i:0#.f|membership|" & UserManager.userPrincipalName,
Department: "",
DisplayName: UserManager.displayName,
Email: UserManager.mail,
JobTitle: "",
Picture: ""
}
}
)
)
I tried your code but now the line manager column is not patched to SharePoint and no errors are showing
I think your problem is using Office365Users.MyProfileV2().id which fetches the current user's (the person who is running the app) manager information instead of each user's manager information.
To patch each user's manager correctly, the code should fetch the manager of each user individually within the loop. Here's the corrected version
ForAll(
Filter(
Office365Users.SearchUser(),
AccountEnabled = true
),
With(
{
ExistingItem: LookUp(
'Employee information list',
Email = Mail
),
UserManager: Office365Users.ManagerV2(Id)
},
If(
IsBlank(ExistingItem),
// If the user does not exist, create a new item
Patch(
'Employee information list',
Defaults('Employee information list'),
{
Display_name: DisplayName,
Phone_number: MobilePhone,
First_name: GivenName,
Department_Name: Department,
'designation ': JobTitle,
Email: Mail,
'Line Manager1': {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: "i:0#.f|membership|" & UserManager.UserPrincipalName,
Department: "",
DisplayName: UserManager.DisplayName,
Email: UserManager.Mail,
JobTitle: "",
Picture: ""
}
}
),
// If the user exists, update the existing item
Patch(
'Employee information list',
ExistingItem,
{
Display_name: DisplayName,
Phone_number: MobilePhone,
First_name: GivenName,
Department_Name: Department,
'designation ': JobTitle,
Email: Mail,
'Line Manager1': {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: "i:0#.f|membership|" & UserManager.UserPrincipalName,
Department: "",
DisplayName: UserManager.DisplayName,
Email: UserManager.Mail,
JobTitle: "",
Picture: ""
}
}
)
)
)
)
If this helps, please mark it as the solution by clicking "Accept as solution." A "Thumbs Up" would be greatly appreciated if you found the content helpful. Thanks!
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional