Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building 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: ""
}
                }
            )
        )
    )
)

 

  • MarwaAlhajri Profile Picture
    on at
    Re: Patch employee manager info

    MarwaAlhajri_0-1720001604235.png

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

  • royg Profile Picture
    on at
    Re: Patch employee manager info

    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
    Re: Patch employee manager info

    MarwaAlhajri_0-1719990943914.png

    The result in my manager email 

  • royg Profile Picture
    on at
    Re: Patch employee manager info

    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
    Re: Patch employee manager info

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

  • Giraldoj Profile Picture
    561 Super User 2025 Season 1 on at
    Re: Patch employee manager info

    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
    Re: Patch employee manager info

    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 

  • royg Profile Picture
    on at
    Re: Patch employee manager info

    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
    Re: Patch employee manager info

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

  • Giraldoj Profile Picture
    561 Super User 2025 Season 1 on at
    Re: Patch employee manager info

    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!

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard