Help

Create multiple records based on a quantity field with a Script

Topic Labels: Scripting extentions
18046 46
cancel
Showing results for 
Search instead for 
Did you mean: 
Sam_Cederwall
7 - App Architect
7 - App Architect

I would like to create a script that creates a number of records based on a quantity field. Essentially, if there is a record that has a quantity (x) of more than 1, I want to copy and create that record x amount of times within the table, then lower the quantity for the record and each subsequent record to 1.

I have some of the script set up. Are there any ideas on how I could specify the # of records to create, based on the quantity field, using createRecordsAsync in the Scripting Block?

As usual, thanks for the help!

46 Replies 46

Hi,

you missed for loop counter increment.

@Lisa_Bauer - a couple of things to note:

  • As per @Alexey_Gusev, you are missing the incrementer on the loop, so this:

for (let i = 0; i < quantity-1)

should be something like this:

for (let i = 0; i < quantity-1; i++)

I can see that on the last line of the script you also have the 3 backticks, which may not be in your actual script, but are shown here, so worth checking that they are not there.

One other thing to note - your create records action - last line - works on the recordsArray, which is all good, but the action is limited to creaitng 50 records, so if you array could contain more than 50 records, you need to do something like:

while (recordsArray.length > 0) {
    await table.createRecordsAsync(recordsArray.slice(0, 50));
    recordsArray = recordsArray.slice(50);
}
Lisa_Bauer
6 - Interface Innovator
6 - Interface Innovator

Thank you both for your helpful reply and assistance!

This is excellent and very close to what I’m trying to do.
Is there a way to produce all the records at once?

let record = await input.recordAsync(‘Please select a order’, orders);

and just to get greedy: by button?

Hi @Houston_Llew - there’s a variation on this theme higher up in the thread that I think does what you are asking for:

Is this what you mean?

Jack_Tranckle
4 - Data Explorer
4 - Data Explorer

Hello all, I am looking at doing almost the same as above, however instead of "quantity", I would like it to be a linked cell with an array of data (in my case names). What would need to be changed to achieve this? 

Could you help me modify this script?