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 Platform Community / Forums / Power Apps / Patching a record usin...
Power Apps
Unanswered

Patching a record using LookUp not working?

(0) ShareShare
ReportReport
Posted on by

Hi

Can anyone see why this wouldn't work correctly. Instead of updating the existing record, it is patching a new one each time. Upon  choosing a new date in the gallery, I store 'existingdate' by setting a variable on the ON CHANGE function of the date picker and use the code: setExistingDate(ThisItem.FROM). This works and stores the previously stored date. I also do the same for the END DATE. 

 

Then, to update the record (which is in a different data source):

 

Patch(CRUD_3S,

LookUp(CRUD_3S, CrewName=Gallery2.Selected.Name && DAY_TYPE=3 && StartDate = ExistingStartDate && EndDate = ExistingEndDate),

{StartDate: DatePickerFROM.SelectedDate,
EndDate: DatePickerTO.SelectedDate})

 

I can see that the existing dates are being stored correctly and I can see the record in the "CRUD_3S" data table with all of the other criteria met (crewname, day type etc.). However, each time, a new record is created?

 

Many thanks!

Categories:
  • timl Profile Picture
    37,287 Super User 2026 Season 2 on at

    Hi @jed76 

    To diagnose this, I'd add a button and attempt to store the record in a variable.

    This would then give you a chance to inspect varRecord in the variables section of the designer.

    What I suspect is that LookUp isn't finding the target record which results in your formula creating a new record each time. This interim step should enable you to inspect the existing start/end date sections of your LookUp criteria. I'd imagine the cause lies somewhere there.

    Set(varRecord,
     LookUp(CRUD_3S, 
     CrewName=Gallery2.Selected.Name && DAY_TYPE=3 && 
     StartDate = ExistingStartDate && EndDate = ExistingEndDate
     )
    )

     

  • jed76 Profile Picture
    on at

    Thanks. Yes, it can't be finding the record. I have inspected all of the variables within the editor and I can see they all appear to be correct. I will try your method!

  • jed76 Profile Picture
    on at

    Hi

    Tried that and upon inspecting the varRecord, everything is correct so there should be a match?!

  • jed76 Profile Picture
    on at

    I've just tried the same logic but with REMOVEIF and this removed the record!

     

    However, with an UPDATEIF, it still creates a new record?! 

  • muzammilasif Profile Picture
    73 on at

    Try using ID of record, this helps in matching exact record for patch, moreover you can try following as well if you are creating new record and updating them at same time 

    Set(NewRecord,Patch('Records',Defaults('Contract Records'),
    {
    // Custom column:'Value'
    }
    ));
    
    Patch('Records', Lookup('Record', Id = NewRecord.Id), 
    {
    // Custom column:'Value'
    }
    ));

     

    Please click Accept as solution 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 Thumbs Up.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 396 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 323

#3
WarrenBelz Profile Picture

WarrenBelz 193 Most Valuable Professional

Last 30 days Overall leaderboard