I need to automatically duplicate a record on a table depending on the value of a column while using a patch function and I just can't figure out how to do it.
Case Scenario:
Gallery: Gallery_plan_attach
| Title | Sample ID | Repetitions | Product |
| Example 1 | ABC_123 | 2 | Product A |
I need to recreate the exact same record into the second table and create X number of duplications based on the Repetitions column.
It should look like this
Destination Table: MV_DATA_CAPTURES
| Title | Sample ID | Repetitions | Product | Repetition No |
| Example 1 | ABC_123 | 2 | Product A | 1 |
| Example 1 | ABC_123 | 2 | Product A | 2 |
It copies it and adds sequence values into column Repetition Number based on the value of the Repetitions column.
This is what I have so far 'OnSelect' of a button:
Set(LoopTimes,CountRows(Gallery_plan_attach.AllItems));
ForAll(
Sequence(LoopTimes,1,1),
Patch(MV_DATA_CAPTURES, Defaults(MV_DATA_CAPTURES),
{{Title: Title,
Sample_ID: Sample_ID,
Repetitions: Value(Repetitions),
Product: Product,
'Replication No': Index(Gallery_plan_attach.AllItems)
} )
)