Instantly make a button to copy a row with lots of columns

Not a hack per se, just a smart way to speed up formula creation to copy a row (e.g. from the main table to a log table), using some regex.

Here’s a video how you can make such log table in 2 minutes:

  1. Copy the table to a text editor or right into an offline / online editor that supports regular expressions (I prefer regex101.com, not affiliated). Remove everything but the headers

  2. Set up replacement with regular expressions:
    Search: ([^\t]+)\t?
    (means capture each element between tabs)
    Replacement: [\1], thisRow.[\1],
    (means insert the captured column name twice, enclose in brackets)

  3. Use replacement result in an .AddRow() formula.

One caveat: this won’t have newlines. If you try to insert formula text that contains newlines, Coda won’t properly process it as a formula.

15 Likes

Bookmarked :slightly_smiling_face:
*Note to self: I need to learn to use Regex

1 Like

True that, regex is a must have in any power user’s tool belt. It is actually not that hard to learn, and tools like regex101 help a lot.

I guess you’re right, just need to find time for that among million other things :upside_down_face:

Everyone needs to learn to use RegEx. Even people who already know it. No one has ever come to truly know it. :wink:

3 Likes

@Paul_Danyliuk I’ve noticed that some of your column names starts with underscore, I guess it’s in order to differentiate them somehow but I wonder what exactly?

This is indication to myself not to use this column in user-facing sections (e.g., in views that are meant to be read-only or aren’t otherwise meant to be filled in by doc users). Only columns without underscores are safe to use outside of the “for builders’ eyes only” sections.

Maybe I didn’t do that so strictly with this very sample, but usually that’s the idea.

P.S. Also to mark columns that aren’t suitably formatted for user-facing output, and to hint that there’s another column without the underscore that should be used instead. So yeah, in the end it’s to prevent myself from showing columns that are not meant to be shown to users.

4 Likes

Smart.

I see a similar parallel in Google Apps Script where the Google designers specifically implemented a way to help non-technical users avoid running functions that require arguments. By appending an underscore to the end of the function name, it is hidden from view in the run options and toolbar.

Runnable …

image

Not Runnable …

image

This is amazing @Paul_Danyliuk ! Super useful!

I’m now getting a “Pattern Error” in the substitution part, any ideas on how to fix it?

Try selecting a different flavor. I see that’s what changed since I recorded that video.
This works:

P.S. In PCRE2 it’s [$1] not [\1]

1 Like

It worked! Thank you so much, this workflow has saved me and my clients so much work!

Thanks so much for this - it really will help me a lot but I just can’t get it to work (sorry, I have zero experience with coding so I am reaching out in the hope you can help)

As you can see from the screenshot below, the formula is failing to recognise that anything in the is a value/column

Screenshot 2021-08-18 at 11.15.10

Is there anyway you could help please?

Thanks