Automated Row Duplication Based on Integer Value In Column

Use Case:
I sell widgets and the quantity of widgets generates will generate (with a formula) the number of boxes that will be required to ship the order. I have a view filtered for orders ready to ship and export this information to a .csv and then import the orders into my shipping application, stamps.com. Upon import, each row corresponds to a shipping label. The challenge is that I have to duplicate the rows x number of times to match the required number boxes.

Is there a way to way to automate this process? My hunch is that it can be done with a script. However, I have 0 experience working with scripts. I’m happy to learn if this is the case and someone wants to point me in the right direction. I also have Zapier at my disposal if this helps solve the problem.

Help or support would be greatly appreciated.

Yep, this is definitely a great use-case for the Scripting block.

In your table setup, I’d suggest having 2 fields in place:

  1. The “Duplicates to Make” integer field you already mentioned
  2. A “Duplication Done” checkbox field to ensure you don’t create erroneous duplicates

The script will operate on a View filtered to show only records WHERE “Duplicates to Make” has a value AND WHERE “Duplication Done” == False (or 0).

The script can query all the records from that view, loop over them, and for each, create a number of new records equal to the number in “Duplicates to Make”, populating those new records with data from the original. Once the duplicates are made, the script could check the “Duplication Done” checkbox field.

I don’t have time right now to dive into the script itself, but I bet you could make a good start of it if you dive into the documentation :slight_smile:

Thank you Jeremy for the quick response and for pointing me in the right direction. I’ll post the solution (when I work it out) for the benefit of the AirTable community.

1 Like

Yes please, I’m searching for this too!

After a few unsuccessful attempts at writing a script from scratch, I’ve come to guess that I’m a bit over my head. Without first learning some Javascript basics I’m kinda swinging blind. Instead of bothering everyone with questions that I would learn if I just starting learning js from the beginning, I went searching (again) for a script I could copy and paste. I found this great post (only a few days old) by Kuovonne Voderbruggen (@kuovonne ) that does most of what I’m trying to accomplish. See the post here:

I am stuck trying to figure out how to define the view that the records are pulled from. I’ve tried several variations of the following line of code with no luck.

let view = table.getView(‘Orders to Ship’);

Any help would be appreciated.

That looks right to me … as long as table is actually holding a table object!

The editor should give you pointers as to whether you’re on the right track – if you have a valid table object, when you call .getView(...) off of it, and you hit that first quotation mark, the Intellisense context menu in the editor should show you all of the View names available in that table object, like so:

I didn’t have to do anything special to get those to come up as options – I just instantiated a valid table object, called .getView() off of it, and as soon as I typed the first ", that context menu popped up showing me the names of all my views in that table.

So if that line you have there isn’t working, I’d suggest that maybe you aren’t properly instantiating your table object first.

@Paul_Miller
I’m glad you found the script useful.

You were on the right track, but you also have to query the view instead of the table.

I updated the gist to include the ability to specify a view name at the top of the script.

Your update works like a charm. Thank you so much Kuovonne!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.