Airscript Examples
Last updated
Last updated
Sometimes you need to project time out into the future. When scheduling an event and you want to specify a time, Airscript can help you do that through the date functions.
For example to get a get a time two days from now, we could write the following Airscript:
In this example we are taking the current time with NOW() adding 2 as number value and "days" as the unit value.
Imagine you have a form where you only want to display an additional item if a condition is TRUE.
On most elements in the app builder there is a Visible option.
Sometimes you will want to want to do something more than a TRUE or FALSE. In this expression block you can do a bunch of different things.
For example, lets say you have a field you only want to display for persons named "Bob", you could write the following Airscript:
This is checking to see if the name is Bob. STRING_COMPARE() takes in two strings and returns a number. If the strings are equal the number is 0.
Another example may be if you have a list of books and you want to display a message to the user if there are no books selected. Here would be the Airscript to check
The function ISNOTEMPTY() takes one parameter and checks to see if it is empty, if so it returns FALSE, Otherwise it returns TRUE.
Here are several other ways you could do the same check:
Remember that the check is for Visible. If the expression evaluates to TRUE, the element will be visible. If it evaluates to FALSE, it will be hidden.
Another common use case is taking a number amount and formatting it for a user to read. It makes sense to keep the numbers in a number format in App Objects for various math operations. Still reading 10000000000 is harder than reading 10,000,000,000. Other countries even use different separators. Luckily Airscript has a FORMAT_CURRENCY() function. You use it like this:
In this case "USD" is the currency string. You will get $10,000,000,000.00 out.
Another common example is combining text variables together. Imagine a case where you have an input with three text inputs, one for first name, middle name, and last name. You want to display them combined at the end.
In order to get out the full name, you can use escape characters in your string to display each part of the name:
In Airscript Strings {{ }} are known as escape tokens. Inside the escape tokens you have access to Airscript accessible variables and functions.
There are a couple of other ways to do this. For example:
In this example we create an array with the variables and use the JOIN() function to combine them with a space.
Depending on your use case, you might want to display dates differently to your user. Sometimes you want to display a shortened, numerical interpretation, other times you may need to include the full date and time. Airscript provides you tools to configure that, regardless of your needs. You can also combine different date functions together. Here is an example:
Given today’s date (May 20th, 2020) this would result in:
05/20/2020
For more details on how to use the above expressions, check out our previous Airscript Examples, along with looking at the reference material for the Date Functions.
Conditional expressions in Airscript allow you to select one of two expressions based on the boolean result of the first expression. If the expression evaluates to TRUE the second expression will evaluate, if it’s FALSE the third expression will evaluate.
Let’s look at an example. Below we have an simple example of what a ticket might look like:
We can create an expression where we check whether the ticket matches the correct id. If it has the correct id, then it’ll return the description string, otherwise it’ll return the string "Not Found"
Because the second and third parameters are also expressions, we can nest these IF() expressions as well. We could check to make sure that the description also exists, and have a different response if there is no description present.
Airscript also provides a complex filtering and manipulation offering similar to SQL. This provides you the power of a query language, on top of the already powerful Airscript.
Let’s take an example where you have a list of objects that contain a question and selected answer. Here we see a list of questions, with only some of the answers filled in:
We can filter that list of questions down to only the questions that have answers, and then we can extract only the answers from those:
That would give us a filtered result of:
Since, we’re still working with Airscript, we can also perform more advanced operations on the filtered data. We could join those answers into one string for use within a label. Our filter expression would change to this:
Which would give us the string: