Formulas [Experiments]

Formulas is now part of our Experiments 🔬

Experiments is an Alpha testing program where you can test pre-release versions and have early access to the newest features.

It is really important for us to get feedback from early adopters to improve our products before shipping to the world. Learn more about Experiments and the possible downsides at this link.

What are Formulas?

Formula block allows you to make complex operations with values inside Landbot, like you do in other platforms like Google Spreadsheets or Excel, and store the result in an outcome variable.

Whereas before you could only transform data with Javascript or with external API's, now you will be able to do it, easily, using Formulas.

How to create a Formula

1. Select the variable where you want to store the outcome of the formula

2. Set the formula

3. Save and use

Elements of the Formulas block

1. Output

In the Output field you can define or create the variable where the result of the formula is going to be stored

2. Formula

Here is the editor, where you can create and edit formulas

3. Formulas Browser/Docs

In this section, you will see all the available methods you can use in the Formulas block.

Things you can do when building your formulas

1. Formulas can use fixed values

2. Formulas can use Landbot variables

3. Formulas can use formulas inside formulas

4. Formulas can use same output variable

5. Formulas can be chained one after another

6. Formulas can be great with the Conditional block

Things to be aware of when building your formulas

1. Blue ticks!

To be a valid formula, make sure both ticks are blue

2. Output variable type

Make sure the type of the variable is the right format to the type of formula you are using.

For example, if you are creating a math operation, you want the variable of the output to be a number, not a string type.

3. Outputs, there are two possible outcomes when using the Formula block:

Green Output => Success

Red Output => Fail

4. True and False, are strings that start with Capital letter!

In case you are using a type of formula that the outcome can be a boolean value, remember that True or False will be strings that the first letter will be Uppercase.

5. System variables need " "

If you are planning to use Landbot System variables like @today, add the " " between those variables:

6. Not created variables need " "

If the variable is not created yet, it needs " " also to be a valid formula

7. Test before you go into production!

Test always to make sure the Formula works as expected

Types of Formulas

Comparison

Comparison formulas available:

  • IsEqual
  • IsNotEqual
  • IsGreater
  • IsGreaterOrEqual
  • IsLess
  • IsLessOrEqual
  • IsSet

Examples of use case of Comparison formulas:

Check if input from the user is the same as a number

IsEqual(@userinput,2)
Check if age is above 18

IsGreaterOrEqual(@age,18)
Check if the variable email is set or not

IsSet(@email)

Logical

Logical formulas available:

  • And
  • Not
  • Or

Examples of use case of Logical formulas:

Check if email contains "gmail.com" AND the age is over 18

And(Contains(@email,"gmail.com"),IsGreater(@age,18))

Check that the user did NOT select a color "red"

Not(@color,red)
Check if the "city" selected is Barcelona OR Madrid

Or(IsEqual(@city, "Barcelona"),IsEqual(@city,"Madrid"))

Math

Math formulas available:

  • Product
  • Quotient
  • Remainder
  • Subtract
  • Sum
  • ToFloat
  • ToInteger

Examples of use case of Math formulas:

Apply 20% discount

Product(@price, 0.80)
Get % of correct answers

Quotient(Product(@correctanswers,100),@maxpoints)

Add +1 every time user passes through this step

Sum(@counter,1)

String

String formulas available:

  • Contains
  • Length
  • Lower
  • Replace
  • Slice
  • Split
  • ToString

Examples of use case of String formulas:

Ensure the email is in lower case for proper validation

Lower(@email)

Get list out of options selected in Multiplechoice

Split(@options, ", ")

Note, if you want to limit the number of options, this will be handy if you add use also the Length formula and with a Conditional block, you redirect the flow according to the maximum number of options you require. Like in th example below:

Where the formula is:

Length(Split(@options, ", "))

Check if text is too long

Length(@userinput)
Mimimi

Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(@toreplace, "a", "i"),"e","i"),"o","i"),"u","i"),"y","i"),"é","i"),"è","i"),"á","i"),"à","i"),"ò","i"),"ó","i"),"ù","i"),"ó","i"),"ü","i")

Array

Array formulas available:

  • Contains
  • GetValue
  • Length
  • List
  • Slice
  • Push

Examples of use case of Array formulas:

Get length of an arrays

Length(@array)

Create an array out different strings

List(@input1,@input2,@input3)

Add last user input to an array

Push(@arrayinputs, @lastinput)

Object

Object formulas available:

  • GetValue
  • ToJSON

Examples of use case of Object formulas:

Get value from the key "Name"

GetValue(@response, "Name")

Get value from first item of the array that is in the key "colors"

GetValue(@response,"colors",0)

Transform string to a JSON

ToJSON('{"city":"Valencia","country":"Spain"}')

Regex

Regex formulas available:

  • RegexTest

Examples of use case of Regex formulas:

Check if the input is of 10 digits number

RegexTest(/\d{10}/,@number)

Check if the input is a valid UK postal code

RegexTest(/([A-PR-UWYZ][A-HK-Y0-9](?:[A-HJKS-UW0-9][ABEHMNPRV-Y0-9]?)?\s*[0-9][ABD-HJLNP-UW-Z]{2}|GIR\s*0AA)/,@text)

Check if the input contains a word that is "stop" or something that starts with "stop"

RegexTest(/^stop.*/,@text)


How did we do?


Powered by HelpDocs

Powered by HelpDocs