I tried that new code and it works well.
Much cleaner than my effort.
Never knew about Coalesce, but after Googling it, it appears to return the item which has data.
The only thing I am confused on is the last statement.
If(IsBlank(MyItem), Set(LastAddedItem, patchResult))
When patchResult is first called, does it hold a returned record value?
The other thing I noticed is that when I put msg into a label, the label did not show any text.
Yes, Coalesce is a wonderful function that makes formulas so much cleaner. You can read more about it in the function docs.
As for that last statement - yes, you are specifically doing an UpdateContext on the local variable called patchResult. Then you are assigning the return of the Patch function. Patch will return the entire record that you Patch...so, in this case, patchResult will have the patched record.
As for the label...that should show what is in the msg context variable. At the very least, since you don't specifically clear it, it should show the very last text you updated it to.
Ok I think I get it - the last statement is where you are looking for the record so that you can get the last added id which is used at the start of the procedure.
Yes I have msg as the text value of the label, but it does not seem to show the text from the code.
It did with my code, but in this case it is not showing.
Perhaps I can delete the label and try with another one.
The "baked in" logic in the formula is that - if there is a DataTableID, then we use that, if not, then we use the LastAddedItem.ID, if not then myItem will be blank and therefore we will create (defaults) a new record with Patch.
So, based on that, if myItem is blank, then we know we just added a record and therefore we should set the LastAddedItem to the just added record in patchResult.
This is totally based on the fact that you call this "LastAddedItem". If we wanted the last updated item, then we would not have the If(IsBlank(MyItem), Set... part there, we would just simply Set it.
Yeah, try something with that label. That seems a little strange as it should be showing something. Also, perhaps try renaming the variable in your formula to lclMsg and then update your label to that. (I, personally, use the lcl prefix to any Context variable so that I know, very quickly, that it is a context variable local to that screen only)
Featuring samples like Return to the Workplace and Emergency Response Applications
We're excited to announce our first cross-community 'Can You Solve These?' challenge!
Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.
We are excited for the next Super User season.
Features releasing from October 2020 through March 2021