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 :
Power Apps
Unanswered

Patching problems

(1) ShareShare
ReportReport
Posted on by 61
HI everyone. I'm trying to capture some details of first time users, I'm using the following code:
 
// Store details for First Time User
If(
    IsBlank(LookUp(AppUsers,'User Email' = User().Email).'User Email'),
    Patch(AppUsers, Defaults(AppUsers), {'User Name': User().FullName, 'User Email': User().Email, Office365ID:User().EntraObjectId})
);
If(
    IsBlank(LookUp('Leave Allowances', 'User Email' = User().Email).'User Email'),
    Patch('Leave Allowances', Defaults('Leave Allowances'), {'User Email': User().Email, Office365ID: User().EntraObjectId}),
    Patch(LookUp('Leave Allowances', 'User Email' = User().Email), {'User Email': User().Email, Office365ID: User().EntraObjectId})
);
 
The AppUsers table gets updated fine, no problem there. The Leave Allowances table doesn't update the way I would like it, it adds user email and ID to a new record rather than updating an existing record. Any help as to why this is?

Thanks
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    152,839 Most Valuable Professional on at
    Patching problems
    Assuming you are using SharePoint here, try this - it should update any existing record, or write a new one if none exists.
    With(
       {
          _User:
          LookUp(
             'Leave Allowances', 
             'User Email' = User().Email
          )
       },
       Patch(
          'Leave Allowances', 
          {
             ID: _User.ID,
             'User Email': User().Email, 
             Office365ID: User().EntraObjectId
          }
       )
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • WayneSS Profile Picture
    61 on at
    Patching problems
    Thanks @WarrenBelz but unfortunately that also keeps adding a new record and doesn't update the existing one.
  • Ytalo Silva Profile Picture
    181 Super User 2025 Season 2 on at
    Patching problems
     
    Hello, have you tried using the update Patch in this format?
     
    Patch(
        'Leave Allowances', 
        LookUp('Leave Allowances', 'User Email' = User().Email), 
        {
            'User Email': User().Email, 
            Office365ID: User().EntraObjectId
        }
    )
    I hope this helps!
  • Verified answer
    WarrenBelz Profile Picture
    152,839 Most Valuable Professional on at
    Patching problems
    Firstly, do you want to also create new records if none exist (this is what I initially assumed). If so you can go the "very long" way as below (probably a bit of overkill involved here), but I use that syntax regularly on Prod Apps and it works as expected
    With(
       {
          _ID:
          LookUp(
             'Leave Allowances', 
             'User Email' = User().Email
          ).ID
       },
       Patch(
          'Leave Allowances', 
          If(
             IsBlank(_ID),
             Defaults('Leave Allowances'),
             LookUp(
                'Leave Allowances', 
                ID = _ID
             ),
             {
                'User Email': User().Email, 
                Office365ID: User().EntraObjectId
             }
          )
       )
    )​​​​​​​
    If you simply want to update existing records which will always be there 
    Patch(
       'Leave Allowances', 
       LookUp(
          'Leave Allowances', 
          'User Email' = User().Email
       ),
       {Office365ID: User().EntraObjectId}
    )
    Note - why bother with 'User Mail' as it is already the correct value.

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 836 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 231 Super User 2025 Season 2

Last 30 days Overall leaderboard