Struggling to Loop Through a Task Table and Add Rows to a 3rd Table Using FormulaMap

PROBLEM STATEMENT

I have three tables in Coda:

  1. DB: Client Testers (USERS)

    • Key columns:
      • Partner (text or lookup)
      • Client Tester Email (text or email)
      • Button (to generate rows in another table)
  2. DB: B2B Nudges by Partner (TEMPLATE OF KEY TASKS EACH TESTER NEEDS TO DO)

    • Key columns:
      • Partner (text or lookup)
      • Workstream
      • Task (single-value, not multi-select)
      • Other “Nudge” details
  3. DB: B2B Nudges To Send (ALL TASKS THE TESTERS NEED TO DO BASED ON THE 2 TABLES ABOVE)

    • Key columns:
      • Client Tester Email
      • Task
      • Other columns to be auto-populated or manually added

GOAL

From each row in DB: Client Testers, I want to create a row in DB: B2B Nudges To Send for every matching Task in DB: B2B Nudges by Partner. The match is based on the Partner in Client Testers and B2B Nudges by Partner. Specifically:

  • The Button in DB: Client Testers, when clicked, should loop over DB: B2B Nudges by Partner rows where Partner = thisRow.Partner.
  • For each matching row (i.e. each Task), create a new row in DB: B2B Nudges To Send, copying over:
    • The Task from DB: B2B Nudges by Partner.
    • The Client Tester Email from DB: Client Testers.

WHAT I TRIED

I used a formula similar to this:

[DB: B2B Nudges by Partner]
.Filter(Partner = thisRow.Partner)
.Task
.FormulaMap(
CurrentValue,
AddRow(
[DB: B2B Nudges To Send],
[DB: B2B Nudges To Send].Task, CurrentValue,
[DB: B2B Nudges To Send].[Client Tester Email], thisRow.[Client Tester Email]
)
)

But I keep encountering errors like “FormulaMap only takes 2 arguments” or the action simply does nothing. I have checked for extra commas and spelling issues, but it still is not populating DB: B2B Nudges To Send as expected.

1 Like

Hello @Klas_Hesselman

The FormulaMap() function simply iterates over a list. If you didn’t know, there are two ways to use these kinds of formulas: List.FormulaMap([thing to do]) or FormulaMap(List, [thing to do])

You are not following either of these formats. Your list is [DB: B2B Nudges by Partner] .Filter(Partner = thisRow.Partner).Task, so you have these two options:

  • [DB: B2B Nudges by Partner].Filter(Partner = thisRow.Partner).Task.FormulaMap(AddRow(...))
  • FormulaMap([DB: B2B Nudges by Partner].Filter(Partner = thisRow.Partner).Task, AddRow(...))

In my personal opinion, I prefer using the ForEach() formula instead of FormulaMap(). Additionally, I like to use the Let() formula to make certain snippets more readable by assigning them meaningful variable names, especially if you use it more than once (which is not your case here)

Also, your doc is not public. I think you just published it, but you need to change the sharing permissions also.

Best Regards
Arnhold

3 Likes

thank you @Felipe_Arnhold - that worked…i spent 1hr with ChatGPT trying to figure that one out…

2 Likes

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