Skip to main content

Notifications

Power Apps - Building 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
  • WarrenBelz Profile Picture
    WarrenBelz 145,580 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
  • Ytalo Silva Profile Picture
    Ytalo Silva 65 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!
  • WayneSS Profile Picture
    WayneSS 61 on at
    Patching problems
    Thanks @WarrenBelz but unfortunately that also keeps adding a new record and doesn't update the existing one.
  • WarrenBelz Profile Picture
    WarrenBelz 145,580 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

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,580

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,909

Leaderboard