The formula which will unlock more automation and Coda magic than any other
Before everything - What is this formula?
FormulaMap() allows you to define an action or formula and then run that action/formula individually on each item in a list.
Take this list of numbers for example:
1234
First choose what you want to do to each item in the list
Add
0
3
to
each number
Notice how it changes our original list of numbers
Output:
4567
First - let’s just learn how it works.
The FormulaMap() formula is like saying:
Hey Coda, Im going to give you a list of items - Can you do the exact same action with each item in the list?
FormulaMap() takes two arguments
List
A list of items that you want Coda to indiviudally perform an action on
Formula
This is the formula Coda will perform on each item in the given list
Lets look at a quick example with a list of states:
AlaskaAlabamaArkansasArizona
Heres some quick actions FormulaMap() can do to each word
FormulaMap() making them Upper Case:
ALASKAALABAMAARKANSASARIZONA
FormulaMap() making them Lower Case:
alaskaalabamaarkansasarizona
FormulaMap() finding the words length:
6787
FormulaMap() checking if the words starts with “ala”:
truetruefalsefalse
FormulaMap() deleting every vowel from the word:
lsklbmrknssrzn
Don’t forget currentValue
The phrase currentValue has a special meaning within the formulaMap() formula. It is used to access the current value within the list. Take this list for example:
1234
The first time formulaMap() runs, the currentValue is 1
The second time formulaMap() runs, the currentValue is 2
The third time formulaMap() runs, the currentValue is 3
The fourth time formulaMap() runs, the currentValue is 4
currentValue will be used every time you write a formulaMap() formula
These examples are fun and show how the formula works, but now let’s find out how to use it to unlock some magic in your Coda docs and workflows.
Second - Where and how to use this
Let’s look at a concrete example of how you can use this to unlock some magic in your Coda docs. Lets pretend that you are preparing to lead a Jedi school to teach upcoming users of the force to master their powers, but you don’t discriminate between those drawn to the light-side or the dark-side.
Obviously though, depending on which side (dark or light) a student is drawn too, they will need different lessons focusing on different things.
Lets start with a database of lessons where each lesson is tagged either as one meant for the dark-side, the light side, or both
Lessons
0
Lesson
Lesson is for:
Lesson
Lesson is for:
1
Turn on a lightsaber
Dark side
Light side
2
Fight with a lightsaber
Dark side
Light side
3
Learn to Pilot an X-Wing
Light side
4
Learn to Pilot a Tie-Fighter
Dark side
5
Learn to be really cruel
Dark side
6
Learn to be really compassionate
Light side
There are no rows in this table
Now that we have a set database of lessons, lets populate these lessons for individual students depending on what side of the force they are drawn to with the click of a button. This is where the magic of formulaMap() happens.
Students
0
View
Name
Drawn Towards
Add All Lessons
All lessons
View
Name
Drawn Towards
Add All Lessons
All lessons
1
Luke Skywalker
Light side
Added
Luke Skywalker
Luke Skywalker
Luke Skywalker
Luke Skywalker
2
R2-D2
Light side
Added
R2-D2
R2-D2
R2-D2
R2-D2
3
Darth Vader
Dark side
Lessons
[]
4
Leia Organa
Light side
Lessons
[]
5
Beru Whitesun lars
Dark side
Lessons
[]
6
Biggs Darklighter
Dark side
Lessons
[]
7
Obi-Wan Kenobi
Light side
Lessons
[]
8
Anakin Skywalker
Dark side
Lessons
[]
There are no rows in this table
This table below is the database of lessons that each individual student needs to complete. Click the
button above in each students row to see their tasks populated and mark them off as complete/incomplete
DB Lessons
0
Done
Student
Lesson
Done
Student
Lesson
1
Luke Skywalker
Turn on a lightsaber
2
Luke Skywalker
Fight with a lightsaber
3
Luke Skywalker
Learn to Pilot an X-Wing
4
Luke Skywalker
Learn to be really compassionate
5
R2-D2
Turn on a lightsaber
6
R2-D2
Fight with a lightsaber
7
R2-D2
Learn to Pilot an X-Wing
8
R2-D2
Learn to be really compassionate
There are no rows in this table
You can click into the buttons options to see the formula used to assign lessons, but written in plain english, this is what it is doing:
database to find only the rows that are appropriate to the current student. This creates the list that is the first argument of your formulaMap() formula. It is the list that we will perform a individual action on
Now that we have our target list of lessons, we define the action that we will perform on each item. The chosen action in this case is for each applicable lesson, add a new-row for that student to the
Thats it! There are so many possibilities with formulaMap() and the best way to find those is to start building docs of your own using this magic formula!