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 / Patch employee manager...
Power Apps
Unanswered

Patch employee manager info

(1) ShareShare
ReportReport
Posted on by

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:

ForAll(
    Filter(
        Office365Users.SearchUser(),
        AccountEnabled = true
    ),
    With(
        {
            ExistingItem: LookUp(
                'Employee information list',
                Email = Mail
            )
        },
        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|" & Office365Users.ManagerV2(Office365Users.MyProfileV2().id).displayName,
    Department: "",
    DisplayName: Office365Users.ManagerV2(Office365Users.MyProfileV2().id).displayName,
    Email: Office365Users.ManagerV2(Office365Users.MyProfileV2().id).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,
                    Email:Mail,
                    'designation ':JobTitle,
                                   'Line Manager1':{
    '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
    Claims: "i:0#.f|membership|" & Office365Users.ManagerV2(Office365Users.MyProfileV2().id).displayName,
    Department: "",
    DisplayName: Office365Users.ManagerV2(Office365Users.MyProfileV2().id).displayName,
    Email: Office365Users.ManagerV2(Office365Users.MyProfileV2().id).mail,
    JobTitle: "",
    Picture: ""
}
                }
            )
        )
    )
)

 

Categories:
I have the same question (0)
  • Giraldoj Profile Picture
    895 Moderator on at

    Hi @MarwaAlhajri 

     

    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!

  • MarwaAlhajri Profile Picture
    on at

    I tried your code but now the line manager column is not patched to SharePoint and no errors are showing 

  • royg Profile Picture
    on at

    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: ""
     }
     }
     )
    )

      

  • MarwaAlhajri Profile Picture
    on at

    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 

  • Giraldoj Profile Picture
    895 Moderator on at

    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.

  • MarwaAlhajri Profile Picture
    on at

    Hi, I used lowercase and still it will not patch each employee manager name  

  • royg Profile Picture
    on at

    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

  • MarwaAlhajri Profile Picture
    on at

    MarwaAlhajri_0-1719990943914.png

    The result in my manager email 

  • royg Profile Picture
    on at

    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: ""
     }
     }
     )
    )
    )

     

  • MarwaAlhajri Profile Picture
    on at

    MarwaAlhajri_0-1720001604235.png

    still no Line manager name but if I use Office365Users.MyProfileV2().id it will show as you saw up 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 834

#2
Valantis Profile Picture

Valantis 533

#3
Haque Profile Picture

Haque 410

Last 30 days Overall leaderboard