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