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 Apps
Answered

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
    154,496 Most Valuable Professional on at
    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
    Thanks @WarrenBelz but unfortunately that also keeps adding a new record and doesn't update the existing one.
  • Ytalo Silva Profile Picture
    185 Moderator on at
     
    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
    154,496 Most Valuable Professional on at
    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

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!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 529 Most Valuable Professional

#2
Haque Profile Picture

Haque 230

#3
Kalathiya Profile Picture

Kalathiya 217 Super User 2026 Season 1

Last 30 days Overall leaderboard