Duplicating a row x amount of times, and disabling a control for duplicates

Hi all,

I’ve created an inventory database in coda and since it was complicated to remember how to add a new product, created an “intake” table to help make this easy. The problem is some items need to be added only once and others per size. I’ve managed a semi-manual workaround, but is there:

  1. a way to duplicate a row “x” amount of times, where “x” is a number in one of the columns in that row;
  2. disable a button within that row for anything but the original?

Thank you!

Hi @Karina_Mikhli,

I set up an example to play around and see if this is something you’re looking at.
I provided some handy columns and some different behaviours: just choose whatever fits your needs:

Let me know if you need further details of I misunderstood your point.

Aside from this, I’d better understand the underlying use case as maybe it could be designed with a better data model solution.

I hope this helps.
Cheers!

2 Likes

Federico, thank you so much! Will review this now and let you know :).

@Federico_Stefanato it worked! I don’t totally understand all the formulas you shared, but was able to use and/or tweak to what I needed. Thank you!

Hi @Karina_Mikhli,
happy it was useful.

To better clarify what the main formula (the one triggered by the button) does, here’s a walkthrough explanation:

RunActions( // executes - well - a set of actions :)

// 1st Action

Sequence(1,thisRow.Clones,1 ). // Sequence generates a list of items. It's often a useful way to create loops, like in this case. So the Sequence will generate n values from 1 to the number of clones.
FormulaMap( // FormulaMap is executed at each iteration. So: for each number of the sequence...
thisTable.AddRow( // .. adds a row to this table [this is the actual 1st action]... 
thisTable.Name, thisRow.Name, // ... and sets the the values for the relevant columns
thisTable.Clones, thisRow.Clones, // ... [like the above]
thisTable.Source, thisRow // ... [like the above]
))
, 
// 2nd Action

thisRow.ModifyRows(thisRow.Cloned, true) // Modifies the current row by adding a flag
)
// And we're done!

I warmly suggest you to take some time to have a deeper look at the Coda Formulas Reference page: not only lets you familiarise with the language, but sometimes it’s a source of inspiration.

Anyway, feel free to ask if something is still not clear.

2 Likes

@Federico_Stefanato got it and thanks for the explanation. And yes, I’ve often referenced that page but some of the more difficult ones (like the two you mentioned) are hard to envision/understand without seeing them in action.

Thanks again.

1 Like