First, I want to inquire about why you're not using SubmitForm in this scenario. If it's a simple submission, that function often provides an easier approach. However, since you have a specific requirement for using Patch on a Gallery, we can continue with that method.
Given your requirements, let's approach this using Power Apps' built-in FormMode for better clarity.
Here's the process:
1. Set Form Mode Variable: On the OnVisible property of the Screen, you can hard code the variable varFormMode as FormMode.New. It will be up to you to determine how to decide what mode it should be in based on user interactions or other logic.
Set(gloFormMode, FormMode.New)
It will be up to you to determine how to decide when the DefaultMode should be FormMode.New and when it should be FormMode.Edit based on user interactions or other logic for your specific app.
If you only need it on the one screen, use UpdateContext.
UpdateContext({varFormMode: FormMode.New}) //Use FormMode.Edit for Edit mode
I'll be assuming the context variable for the next steps.
2. Go to your Form's DefaultMode property and put this in
varFormMode
3. Use Different Collections Based on Form Mode: You'll want to ClearCollect to different collections based on the form mode:
If(
varFormMode = FormMode.New,
ClearCollect(colNewRecords, ShortFormDetail),
ClearCollect(colBaseRecords, ShortFormDetail)
)
4. Patch Records Based on Form Mode: Wherever you may be Patching the records, use another If to differentiate between new and existing records:
If(
varFormMode = FormMode.New,
Patch(splistdatasource, Defaults(splistdatasource), colNewRecords),
Patch(splistdatasource, colBaseRecords, colChangeRecs)
)
This approach sets up the form mode explicitly and uses it to control behavior for new and existing records.
Now you should have clear and maintainable behavior for editing and creating records based on your gallery.
Adjust the collection names, datasource, and other parts of the formula to match your specific app.
Se if it helps @RJF61