Button To Create Multiple Rows Based On 2 Columns

I’m trying to create a button that creates multiple rows based on 2 different columns.

I know how to get a button to create multiple rows normally. However, I have the following situation:

  • Create a new row for each user in the row AND
  • Create a new row for each option from a list

So the result would be a row for each users for each option that is in a list. For example, if I have 3 users on a task, and 2 options selected, there would be 6 rows created when the button is clicked. 3 Users each with 2 Rows of Options.

I couldn’t get the formulas I tried to work when I tried Sequence(), FormulaMap(), and/or RunActions(). Hoping one of you Coda geniuses can help.

Added a playground demo doc below:

2 Likes

You’re on the right track with an add-to-feedback button in each row (and then if you want, you can click all of those buttons with one button outside the table).

The challenge you may have encountered is having multiple FormulaMap()s. You need a FormulaMap() for each column, but then what does currentValue mean when you’re 2 levels deep?

The solution Coda designed for this is WithName()

WithName lets you give something a new name - for example, giving currentValue a name so that you can still reference it from within another layer of FormulaMap() depth

[Team Members].FormulaMap(
  currentValue.WithName(
    TeamMember,  // The name we're choosing for the current team member in the formulamap
    [Galactic Imperatives].FormulaMap(
      currentValue.WithName(
        Imperative,  // We don't really need to do this WithName, it just helps keep things more readable 6 months from now
        ... make the row in here, referencing TeamMember and Imperative...
      )
    )
  )    
)
3 Likes

A nice write up on how to proceed :heart:
Withname (), makes it so much more easy to keep control on when and where what happens!

And a nice play with "formula map() /“for each()”, Shishir will like it.

1 Like

Thanks for the help, and quickly too!

For any users that read this in the future, below is the final code used in the playground doc.

I had some issues with the formula adding the Task Name in the Feedback Table - Task Name column each time a row was added. So in the example from my first post, you’d have 6 rows each with the Task Name listed 6 times.

I added .First() to fix the issue.

Also, had some issues finding the right syntax (missing value, parentheses, etc.)

thisRow.[Team Members].FormulaMap(
  currentValue.WithName(
    TeamMember,
     thisRow.[Galactic Imperative].FormulaMap(
      currentValue.WithName(
        Imperative,
        
        AddRow(Feedback,
          Feedback.[Team Member],
        TeamMember,
         Feedback.[Task Name],
          thisRow.[Task Name].First(),
        Feedback.[Galactic Imperative],
        Imperative)
    
        )
      )
    )
   )
4 Likes

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