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:
First choose what you want to do to each item in the list
Notice how it changes our original list of numbers
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: FormulaMap() checking if the words starts with “ala”: FormulaMap() deleting every vowel from the word: 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: 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.
Therefore we are going to make three tables
A template database called that holds the list of lessons available A students database called that holds one row per student A lessons database called that holds one row per lesson per student
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
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.
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 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:
First, we filter the 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 table 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!