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 / Gallery - Patch & upda...
Power Apps
Unanswered

Gallery - Patch & update rows depending on if they exist or not

(0) ShareShare
ReportReport
Posted on by

 

I am trying to add a "Save" button next to a gallery that would patch new rows if the record in the gallery doesn't exist and updates existing rows when the record already exists. My Gallery is based on the "Specialty" table that is just a referential of specialties and associated sub-specialties (hierarchy) so that it can display the whole list everytime.

Then, I've an input box in the gallery for each of the sub-specialty that the user can modify. I need to update the "Universe" table when they click the "Save" button both by creating new rows when the record doesn't exist (for 1 unique combo of ID_Country, ID_Scenario, ID_Specialty and ID_Sub_specialty) and update rows when the record already exists.

 

Screenshot PAPPS.jpg

 

I've tried this :

 

 ForAll(
 glr_Sub_Specialty_Universe_1.AllItems;

 With( 
 { r:LookUp(Universe
 ;ID_Country= Text(IDCountry) 
 && ID_Scenario= IDScenario 
 && Id_Specialty=ThisRecord.ID_Specialty 
 && ID_Sub_Specialty=ThisRecord.ID_Sub_Specialty
 )
 ;ThisIdSpec : ThisRecord.ID_Specialty
 ;ThisIdSubSpec : ThisRecord.'ID Sub Specialty'
 
 }
 ; 
 Patch('Universe'
 ;If(
 IsBlank(r)
 ;Defaults('Universe')
 ;r
 )
 ;
 {Universe_count:Value(inp_subspecialty_1.Text) ;
 ID_Country: IDCountry ; 
 ID_Scenario: IDScenario ;
 Id_Specialty : Text(ThisIdSpec);
 ID_Sub_Specialty: Text(ThisIdSubSpec)
 }
 

 )
 )
)

 

 

I've also tried by doing :

- two separate "Patch" in the "If"

- without the "r" (I then repeat LookUp statements)... and it doesn't work. 

What it does is it only patchs the last value (82 in my example) and when we check the monitor it seems like each row updates the one before, ending up with only the last one (125 is created, then replaced by 10, then replaced by 60 and so on).

 

What is really weird is that when we put the same code (without the "ForAll") in separate "Save" buttons by adding it inside the gallery (the blue buttons on the picture) and we click on each button one after the other, it works. It's like the "ForAll" is not working properly in the Global "Save button".

 

Does anyone have any idea why ?

 

Thanks in advance for your help !

Categories:
I have the same question (0)

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 385

#2
Vish WR Profile Picture

Vish WR 367

#3
timl Profile Picture

timl 340 Super User 2026 Season 1

Last 30 days Overall leaderboard