Hello @Nick_F ,
The difference between your solution and Reza's is that the first collection he was doing was in a Gallery with the data source, with the Checkbox control under the On Check property with the following code:
Collect(colUpdates, ThisItem)
What this does is critical for the procedure explained by him. It creates the collection with the data source's metadata.
In your case where is your table located? SharePoint, Dataverse, SQL? Let's assume it's on SharePoint.
When you use Collect in your code (below) to create a new record in your table, Power Apps doesn't know what's that table's metadata, i.e. columns, column types, etc.
If(
ThisItem.Cust in colCustUpdates.Cust,
Update(
colCustUpdates,
LookUp(
colCustUpdates,
Cust=ThisItem.Cust
),
{
Cusname: Cusname.Value,
SCS_ID: SCS_ID.Selected.Value,
Active: Active.Selected.Value,
Auto_ID: Auto_ID.Value,
Shortname: Shortname.Value,
Region: Region.Selected.Value,
SOM: SOM.Value,
Cust: ThisItem.Cust
}
),
Collect(
colCustUpdates, {
Cusname: Cusname.Value,
SCS_ID: SCS_ID.Selected.Value,
Active: Active.Selected.Value,
Auto_ID: Auto_ID.Value,
Shortname: Shortname.Value,
Region: Region.Selected.Value,
SOM: SOM.Value,
Cust: ThisItem.Cust
}
)
)
You can create a temporal collection based on your data source (first record) to create the metadata, then clear the temporal collection and then copying it to your collection with this code:
ClearCollect(colTemp, First(Custs));
Clear(colTemp);
Collect(ColCustUpdates, colTemp);
This way you'll have your metadata in the collection colCustUpdates and it will be blank. Then you can use Collect to save to your collection the new data.
The final trick you're missing from Reza is that when you want to create a new record, you have to drop your table's unique identifier column, e.g. ID in the case of SharePoint, and passing the information to a new collection, like this:
ClearCollect(
colToPatch,
DroppColumns(
colCustUpdate,
"ID",
)
)
Now Power Apps knows that this collection is to create a new record, and you can save to your data source with Patch:
Patch(Custs, colToPatch)
Hope it helps.
Regards,
Fernando
If this helped please give it a thumbs up. Even if your post is already solved it could benefit others.