web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : GNqSqSVLxl4Yu0rTU2Npw7
Power Apps - Building Power Apps
Unanswered

Patch employee manager info

Like (1) ShareShare
ReportReport
Posted on 1 Jul 2024 11:19:16 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 03 Jul 2024 at 10:14:40
    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 03 Jul 2024 at 08:22:27
    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 03 Jul 2024 at 07:16:09
    Re: Patch employee manager info

    MarwaAlhajri_0-1719990943914.png

    The result in my manager email 

  • royg Profile Picture
    on 03 Jul 2024 at 06:52:53
    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 03 Jul 2024 at 06:24:57
    Re: Patch employee manager info

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

  • Giraldoj Profile Picture
    633 Super User 2025 Season 2 on 03 Jul 2024 at 00:04:41
    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 02 Jul 2024 at 10:25:34
    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 02 Jul 2024 at 07:27:54
    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 02 Jul 2024 at 06:18:42
    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
    633 Super User 2025 Season 2 on 01 Jul 2024 at 16:48:30
    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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2