advanced find & replace tools in coda.io
advanced find & replace in coda

Coda Find & replace — enterprise

Respect the layout while replacing multiple variables

7 min readMay 3, 2024

--

Late 2023 I wrote a blog on how to replace hyperlinks. Since I needed a comparable approach more often, we started to improve the experience.

In this this blog I share related findings that are ‘next level’ and permit to conserve style while replacing values. Note however that we cannot inject hyperlinks while maintaining the formatting. This due to native Coda limitations. There is also a second barrier: we lack a proper print to PDF function and without this a contract respecting the pre set style is not so relevant.

There have been positive changes. The function RegexExtract() became official and this function is of great help because it permits to work with capture groups. Capture groups are a special feature within regex that allow you to extract specific portions of the matched text. We use it to find and replace words that are almost the same way written but lack a white space for example.

Demonstration — not an explanation

In this blog — for a change — I demonstrate an approach we developed to replace values in text, while keeping the orignal format. This is not evident and requires a dedicated pack that executes complex code snippets requiring advanced JS knowledge. This pack is not in the gallery and will only be installed in docs we have access to as consultants. The solution is part our toolbox we use to serve organisations dealing with text and variables. This is about contracts, wills, wikis etc. It is an enterprise product starting as of 4500 euro per doc (including 8 hours work).

We had to deal with two technical challenges:

  • Regex
  • JSON

When you want to solve this puzzle for yourself instead of using our approach, there are a few things you need to know. You need to understand Regex, have an understanding of JSON and of course be able to write Javascript to make a pack. The latter is not so easy and showed me how much more powerful JavaScript is compared to the Coda formula language. It is also weaker in the sense that you can create anything and thus get lost easily. Like spreadsheets, it is an double-edged sword.

The main advantages of regex are:

  • It is fast. Unlike my initial approach to turn a text into a list of words by splitting on withe space before evaluating word by word using ForEach(), Regex can evaluate the complete text at once. No need for brute force, but an elegant and speedy combination
  • The syntax we apply in our Coda regex variations is the same as one applies in Python, in C++, C#, R, Perl in JavaScript and in all other programming languages using regex. What you learn in Coda can be applied elsewhere. Many makers use it in Python and in JavaScript.
  • The syntax is well documented. With a bit of research you find out how to create a proper regex syntax. Initially I made a mistake with the double quotes, I had too much the standard Coda syntax in mind. You overcome this like I did with a bit of effort. Yes it takes time, but it is doable and certainly worthwhile.

When I wrote the first blog on hyperlinks, I soon realized that the formatting was gone when I applied the replacement logic. Not only the bullet points, but also the headers, the bold etc. As long as you only work with flat text, this is not an issue. The moment you have a document that is a bit formal, it is formatted with headings and you have to preserve them.

What about JSON?

Since formatting is a central theme in this blog, we talk a bit about JSON.

Unlike the previous blog, in this blog we are not looking for properties to extract, but we evaluate the structure of the JSON. We notice that it is partly based on Slate, this is a JavaScript library that allows you to create rich text editors with a data model that closely resembles the DOM. There are other libraries out there like Quill, but it seems that Slate is more customizable and powerful than Quill and used by Coda.

An example

This example describes a pattern. The pipes are equal to the OR function in Coda. As you see, this is not super easy, although the code is elegant.

preparing for regex

I also permitted myself to apply a more classical coding syntax using + instead of Concatenate() and this to keep the code easier to read. I choice I made because I need the Concatenate() again, one level deeper to glue all the items together. This example only shows how to create a regex pattern. You can create as many ‘rules’, this one works very well when you want to replace something fast. Use Bing (put it on creative) for more inspiration or support to get your syntax right.

The thing is not so much to create a Regex sensitive pattern, the challenge is to replace it with something else you defined elsewhere. You want to filter something.

Here comes the pack into play. The pack permits to use tables in which you link the variables with the right content like a name, an address etc.

An example

In real world examples you likely have the data living in a row and thus you need to transpose that data so it fits the table we use to reference the items.

transposing data.

You are free to skip this step and and fill out manually the variables.

The main idea is that in the buttons we can evaluate each search term and these terms live as items in the display column of the table we reference.

creation of items per template

These items are linked to the table with the references

The set up is a bit of work, but in the end you have per client an easy way generate new contracts etc. It all works fast as well.

The need for print to PDF

It is one thing to be able to put an intelligent format respecting find & replace in place, it is something else to print the data into a Pdf with a proper lay-out.

From a broader perspective we could argue that we have various ways to bring data we can manipulate into a Coda doc:

  • by typing it manually
  • via an import (csv for example)
  • via a form
  • via a pack
  • via a webhook (automation)
  • cross docs

To get data out we can indeed rely on:

  • webhooks
  • cross docs
  • a bit via export
  • some packs
  • print (to pdf)

The latter is not working well enough and does not to seem to appear on any Coda roadmap. Not that we formally have any clue about how the road map logic inside Coda works. Lane shared two times a bit of insight (via a post and a webinar) but all abstract and related to the focus shift — Coda evolving towards an opinionated application mainly supporting meeting notes, OKRs etc., instead of inventory management systems, fiance solutions or HR applications. Meeting notes, OKRs miro boards and so forth are often used by larger teams inside larger companies (enterprises). They already may have applications for contract management and although Coda offers a great solution, this use case is likely not important enough in the greater scheme of things. At least that is how I perceive it.

Without a proper print to PDF, this usage of Coda is actually not so interesting as it seems. It is like having a car and no place to park.

the merge in action

You can see this pack in action in this demo document.

My name is Christiaan and blog about Coda. Since the summer of 2023 often (but not only) about how to Coda with AI to support organisations dealing with texts and templates. The latest major Coda AI update was on Dec 7, 2023. With the announcement of Snowflake as partner on April 10, I expect to see a new Coda AI logic put in place before the summer holidays. The current implementation is not sustainable.

Why I focus on Coda AI you can read here: ⤵️

I hope you enjoyed this article. If you have questions feel free to reach out. Though this article is for free, my work (including advice) won’t be, but there is always room for a chat to see what can be done. You find my (for free) contributions to the Coda Community and on Twitter.

Coda comes with a set of building blocks ー like pages for infinite depth, tables that talk to each other, and buttons that take action inside or outside your doc ーso anyone can make a doc as powerful as an app (source).

Not to forget: the Coda Community provides great insights for free once you add a sample doc.

--

--

I write about Coda.io - AI and (HR )planning challenges. You find blogs for beginners and experienced makers. I publish about once per week. Welcome!