Formula: WithName()
Category: Relational
WithName()
Names a value to be used inside of an expression
It’s kind of like saying...
Hey Coda, I’m going to give you a long formula. I’ll probably want to use it later, so can you remember that formula by a sweet little nickname I give it?
WithName() uses three parameters:
Value
WithName(Value, Name, Expression)
The value you want to rename (usually a short forumula).
Name
WithName(Value, Name, Expression)
The name you want to give the value (i.e., the "sweet nickname".
Expression
WithName(Value, Name, Expression)
The primary formula--you use the renamed value in here.
What Exactly Is This Formula?
WithName() is like the bit.ly of Coda. The mnemonic device of Coda.
Bit.ly
Takes long and complex URLs and shortens them
Mnemonic Devices
Takes long and complex phrases and creates a way to memorize them easily
withName()
Takes long and complex formulas and allows you to reference them easily
How Does it Work?
Here’s a quick example. Let’s say that I want to draft a sentence that tells me how many people in the have a name that starts with “A” and the average age of those people. WithName() allows me to do that easily. There are 1 people whose name starts with 'A' and the average age of those individuals is 11.
And here’s the formula I wrote to draft that sentence
Here’s how that formula breaks down
People Database.Filter(name.StartsWith(”A”)
(2) The sweet little nickname
aPeople
Format("There are. . . ",aPeople.count(), aPeople.Age.Average())
Let’s Get Deeper
WithName() does require extra keystrokes and admittedly does have a small learning curve. So when and where should you use it to actually provide value to your workflows or docs?
First off—if you are writing a longer formula that utilizes filter() within a formulaMap() you will need to use withName() to access the currentValue (see lesson for more info on current value) within the ForEach() loop. Example
Let’s say you wanted to write a canvas-based formula to draft a summary list of the amount of people that match a certain age and let their names be instantly clickable in order to pull up their information.
You will need to use withName() to do that.
Here’s the formula (Right click to see how its written)
There are 2 people that match the age of 20 There are no people that match the age of 21 There are 3 people that match the age of 22 There are 3 people that match the age of 23 There are 3 people that match the age of 24 There is 1 people that match the age of 25 There is 1 people that match the age of 26 There are no people that match the age of 27 There are no people that match the age of 28 There is 1 people that match the age of 29