@kingy61422
Yes, I understand the scenario completely. This is not uncommon.
But, your explanation of what is what is not matching! You are stating that your form is for ExpenseMaster, yet you just stated that "When I submit the form it goes to ExpenseDetails" - That is not possible if your form is for ExpenseMaster!
So, since I am more than intimately familiar with the process...I will just tell you what it should be.
Your Form is set to ExpenseMaster. This is the master record for the details.
You will submit the form with a SubmitForm function. There is no need for doing any other Patch to the ExpenseMaster list. That is why you have the form!
In your OnSuccess action of the Form, you will have a Patch statement to write the ExpenseDetail records into your ExpenseDetails list...from your gallery - not from a collection. The collection only produces a tremendous amount of extra work for you to have to go through. Your gallery is the source of the data.
This makes your OnSuccess action more like this:
Patch(ExpenseDetails,
ForAll(yourGallery.AllItems,
{ID: ID,
Title: Self.LastSubmit.Title,
MasterID: Self.LastSubmit.ID,
ChalkNumber: controlNameInGalleryThatHoldsThisValue.Text, // see details below
TOT: controlNameInGalleryThatHoldsThisValue.Text, // see details below
...etc..
}
)
)
When you use a gallery for "line/child items" the gallery becomes the source of the data. There is no need to do actions in the gallery to copy control data into the collection - it's just extra work.
Each control in the gallery will have the associated value that you need to write.
In the event that there is no particular control in the gallery, but the column is needed (i.e. ID), then make sure your base collection for the Gallery includes that column, and then just reference it in the ForAll record schema.
Your base collection for the Gallery should be based on:
Filter(ExpenseDetails, MasterID=yourMasterFormRecord.ID)