[✅ Solution] How can I create multiple records?

Hello!

In my app, the records have a number field. The user will enter a number (let’s say, x), and I need to make x records in the app using automation. I’m not able to do this using the loop feature, I don’t know what to do.

2 Likes

Hi @agnes.farias,

great to meet you and a very warm welcome to the Tape community! We are really happy that you are here :tada:

The for each loop action actually requires a data array so it can loop over every single element in the array.
But that is not a problem. You can use the script action to convert the number field into such an array.

The required code I got from ChatGPT with the following prompt “turn number value into array in javascript short code”:

With the script action in the automations you can then paste the code 1:1 copy and only have to replace the numberValue with your number field and output the value.

function numberToArray(num) {
  return num >= 0 ? Array.from({ length: num }, (_, i) => i) : [];
}

const numberValue = task_field_number_decimal_value;
const newArray = numberToArray(numberValue);
var_number_of_new_records = newArray

You only need to use the blue marked token your number field and your variable name which you can rename in the header of the script action.

I hope this solves your challenge and if you have any further questions feel free to write here anytime.

Cheers
Leo

4 Likes