I think I need a FormulaMap... but I'm stuck

Hello! I think I need this explained to me like I’m a 5 year old. I have this silly concatenate formula that I’m 99% sure needs a formula map, but I’m so confused by this all. (I struggled with loops when learning to code also and ultimately gave up.)

Can you see how this might be easier to loop through instead of writing it all out like this?

The scenario: I’m trying to make an easy button to copy/paste the information in my table, so I used this formula to concatenate a printout on the canvas.

You’re on the right track with the FormulaMap! Coda actually has two formulas that do the exact same thing, FormulaMap and ForEach – ForEach is a bit more intuitive though, which is what I used.

Basically what the formula is saying, is ForEach( row in [Table2], format the row to look like Concatenate([Question], ": ", [Answer], LineBreak())). and instead of separating each row with a comma .BulletedList()and.CopyToClipboard

I currently have the button outside the table, so you can try using your data in a similar formula to get your info copied!

Hello @heatherfeather !
Maybe something like if you need to loop through all of your checklist. Not sure the code is copy/pastable but you should be able to reproduce it easily !
This gets your checklist, sort it by its id and format each row using the current row in the loop question and answer. This returns a list, that we “flatten” by joining each item with a line break.

 [Work Order Checklist]
  .Sort(true, id)
  .ForEach(
    Concatenate(
      currentValue.Question,
      ": ",
      currentValue.Answer
    )
  )
  .Join(lineBreak()

This is assuming they all have a Question and an Answer. If not you could check that first :

 [Work Order Checklist]
  .Filter(currentValue.Question.IsNotBlank() && currentValue.Answer.IsNotBlank())
  .Sort(true, id)
  .ForEach(
    Concatenate(
      currentValue.Question,
      ": ",
      currentValue.Answer
    )
  )
  .Join(lineBreak()

Another last example, you could also use Format function if you need more advanced templating:

 [Work Order Checklist]
  .Filter(currentValue.Question.IsNotBlank() && currentValue.Answer.IsNotBlank())
  .Sort(true, id)
  .ForEach(
    Format(
      "{1}: {2}"
      currentValue.Question,
      currentValue.Answer
    )
  )
  .Join(lineBreak()

Oops, looks like I was too slow :smile:

Thank you so much @Micah_Lucero and @Martin_Portevin, these answers were both so helpful in understanding what I needed to do. I was able to get my button working perfectly. I appreciate you both!

1 Like

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