Some records imply others: a development with 12 apartments needs 12 unit records. This recipe reads the number from a field, builds a list from 1 to that number with a short script, and loops over the list to create one record per entry. It also marks the development, so changing the number later doesn't create another set.
Note:
Limits apply to loops. A run lasts three minutes at most and can use up to 1,000 actions. Large numbers need several runs. Each
Create recordin the loop counts as one action. The script and the loop itself don't count.Each change can create more records. The marker field in this recipe prevents duplicates. Don't skip it.
What you'll need
A database app
Developmentswith the fieldsName(text),Number of units(number), andUnits created(text).A database app
Unitswith the text fieldsTitleandDevelopment.To build this automation, you need to be a
Workspace adminof the workspace the app is in and haveFull accessto both apps. Anyone who can edit the automation can addExecute script. There's no separate permission for scripts.
Create a record for each unit
Open the
Developmentsapp and click the automations icon at the top right (Create and view automations).Select
New automation, then selectWhen a record is updated.In the trigger, select the field name. Tape preselects one of the app's fields. Select
Number of unitsunderFIELDS, then select the preselected field again to remove it.Under
And if the following conditions are met, selectAdd filter. PickNumber of units, then>(greater than), then 0. SelectAdd filteragain and pickUnits created, thenIs empty.Select
Add action→Execute script. Replace the example code with one line that builds the list and saves it inScript output 1. Where the length goes, use theNumber of unitsfield. In the script editor, type the record name followed by_field_, heredevelopment_field_, and pick the field from the suggestions.enteraccepts a suggestion:var_script_output_1 = Array.from({ length: development_field_number_of_units_decimal_value }, (_, i) => i + 1);Select
Add action→Loop actions. Tape preselectsScript output 1next tofor each.Inside the loop, select
Add action→Create record. Open the app dropdown afterinand selectUnits.Select
Add field, pickTitle, and enter "Unit ". Then type@and selectScript output 1underVARIABLE. Inside the loop, it holds the current number.Select
Add field, pickDevelopment, and type@to insert theNameof the development.Below the loop, outside it, select
Add action→Update record. Open the field dropdown, pickUnits created, and enter "Yes".Select
Create automation.
The result
When you enter 12 in Number of units, Tape creates Unit 1 to Unit 12 in Units, each with the development's name, and sets Units created to "Yes". Later edits of the number don't create more records, because the filter requires Units created to be empty.
Variations
Use a relation field. If
Unitshas a relation field toDevelopments, useSet recordto link each unit to the development instead of copying the name.Start from creation. Use
When a record is createdif the number is always filled in when the record is made.Add the same values to every unit. Add more rows with
Add fieldinsideCreate record, for example aStatus.Create more than one run can handle. Work through the number in batches. Learn more about batches →
Learn more
FAQs
Can I loop without a script?
Can I loop without a script?
Yes, if you already have a list, such as collected records or a field that holds several values. A script is only needed to build a list from a number.
Why did the loop create nothing?
Why did the loop create nothing?
If no record was created, it could be because:
The list was empty, so the loop ran zero times. Check the number in the field.
The filter stopped the run, for example because
Units createdalready had a value.The script failed. Open
Runs, select the run, and check the script step.
Can I undo it?
Can I undo it?
Created records stay until someone deletes them. To remove them, select the units in the Units database app and delete them together. Tape asks Delete selected records? before it deletes them.
Are you a developer using the Tape API for automations?
Are you a developer using the Tape API for automations?
The automation API has its own documentation for developers. Full reference: custom_code in the developer docs →
Still have questions? Find answers and get help from community experts in the Tape community →
