I want to walk through the gallery, and check if an condition is true, insert a row of data to the database, else update an existing data.
I use an If() in ForAll(), and I found that if I use
If( condition, UpdateIf() , Patch() ), it works
But if I change the sequence, it shows error
If( condition , Patch(), UpdateIf() )
Then, I try a few combination, some work but some show error.(see pictures below)
I don't know what the logic is and feel really confused.
Could someone please tell me?
Thanks so much.
Works | Error | |||
First | Next | First | Next | |
UpdateIf() | Patch()_insert | Patch()_insert | UpdateIf() | |
UpdateIf() | RemoveIf() | Patch()_insert | RemoveIf() | |
RemoveIf() | Patch()_insert | UpdateIf() | Patch()_update | |
RemoveIf() | UpdateIf() | RemoveIf() | Patch()_update | |
Patch()_update | Patch()_insert | |||
Patch()_update | Patch()_update | |||
Patch()_insert | Patch()_update | |||
Patch()_insert | Patch()_insert |
==================== Work ====================
// UpdateIf(), Patch()_insert
ForAll(gal_education_3.AllItems As tmp,
If(IsBlank(tmp.serial),
UpdateIf(EducationInfo, serial=tmp.serial, {nation:tmp.nation})
,Patch(EducationInfo, Defaults(EducationInfo), {nation:tmp.nation})
)
);
==================== Error ====================
ForAll(gal_education_3.AllItems As tmp,
If(IsBlank(tmp.serial),
Patch(EducationInfo, Defaults(EducationInfo), {nation:tmp.nation})
,UpdateIf(EducationInfo, serial=tmp.serial, {nation:tmp.nation})
)
);
What datatype is the serial property of EducationInfo?
It's integer
Hi @Mia17 ,
In your UpdateIf where the error is you have {nation:temp.nation} instead of nation=tmp.nation
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.
I am not sure I do you mean.
I set the ForAll items to tmp, so I use {nation:tmp.nation}
I didn't use {nation:temp.nation}😕
@Mia17 ,
OK - I see it now - please disregard my previous post.
I have tested both here and they work either way (so I cannot replicate your issue), but simply use !IsBlank(tmp.Serial) and put them the way that works for you.
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.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
199 | |
71 | |
51 | |
42 | |
30 |
User | Count |
---|---|
268 | |
121 | |
94 | |
92 | |
82 |