You are here:
Create a Formula or Aggregate in an Omniscript
Create expressions to set calculated values and evaluate data across multiple fields using a Formula or Aggregate element. For example, if you are accepting information for a qualifying life event you may want to create a formula that determines if the date entered for the qualifying life event is within thirty days of today's date.
Formula and Aggregate elements support the following constants and types:
-
Omniscript elements and JSON nodes, passed in as merge fields—for example, %Element1% or %JSONnode1%
-
Numbers and integers—for example, 5 + 3.145
-
String literals wrapped in quotes—for example, ' "ABC" + "DEF" '
-
Booleans—for example, true || false
-
Arrays—for example, "[1,2, 3, 4, 5]"
-
Dates—for example, 2/3/24
Formulas with a Data Type of Date are interpreted according to the Date Format, using the Day.js library. To prevent a date from being interpreted, set the Data Type to Text.
-
Null
The elements behave similarly in an Omniscript. However, the Aggregate element should be used for aggregation purposes, such as averaging or summing elements. Formula elements can use both Supported Formula Operators and Omniscript Functions . For example, you may want to determine a contract end date by adding 365 days to a date element. You could do this by using the example formula below:
DATE(YEAR(%DateElement%), MONTH(%DateElement%), DAYOFMONTH(%DateElement%) +365)
If you would like to set a date one week from today's date, you could do so by using the example formula below:
DATE(YEAR(TODAY()), MONTH(TODAY()), DAYOFMONTH(TODAY()) +7)
- From the elements panel, drag a Formula or Aggregate element onto the script structure.
-
In the properties panel, under Expression, add Omniscript functions by clicking on the
function name;
The function pre-populates in the Expression section. To add Omniscript elements inside of the function, use merge fields by enclosing the element in percentage (%) signs.
- If you plan to use this element in a repeatable block, see Evaluate Elements in Repeatable Blocks.
- If you are using a Formula element, continue to build the formula using Supported Formula Operators in the Expression text box.
- If the element should not appear on the Omniscript UI, click Hide.
- Create additional elements that depend on the results of the Formula.
- To test the Formula or Aggregate, click Preview.
- Supported Formula Operators
Formula fields in Omniscript support the following operators: - Omniscript Functions
You can add functions to the Aggregate and Formula elements in Omniscripts.
Supported Formula Operators
Formula fields in Omniscript support the following operators:
Operator |
Meaning |
|---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
^ |
Power |
= |
Equals |
<> |
Not equals |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
&& |
And |
|| |
Or |
( ) |
Parentheses |
For information on supported functions in Omniscript, see Create a Formula or Aggregate in an Omniscript. For information on adding a Formula field to an Omniscript, see Create a Formula or Aggregate in an Omniscript.
Omniscript Functions
You can add functions to the Aggregate and Formula elements in Omniscripts.
For a list of functions for Omnistudio Data Mappers and Integration Procedures, see Supported Data Mapper and Integration Procedure Functions.
To view a list of supported formula operators that can be used with the Formula element, see Create a Formula or Aggregate in an Omniscript.
The tables below detail the different available Omniscript functions and how they work.
Function Name |
Example |
Details |
|---|---|---|
ABS(number) |
ABS(%Friends%) == 6.52534 |
Returns the absolute value. |
BOOLEAN(value) |
Returns true or false. |
|
CURRENCY(value) |
Returns value formatted for currency. 12345 would display as 12,345.00. If you add a decimal value such as 1.2345, by default, the field shows the value 1.23, with two decimal points. If you require all decimal values to be shown, add a value to the Mask field. In this example, the value #.#### in the Mask field will show all four decimal values. |
|
INTEGER(value) |
INTEGER(%Friends%) == 6 INTEGER("12.5") == 12 |
Converts the number given into an integer with no decimal places. Does not round the number up. Also accepts a string. |
NULL |
Renders an object's value null. |
|
NUMBER(value) |
NUMBER(%Friends%) == 128 |
Converts a string into a number. |
POW(number, exponent) |
POW(%Friends%, 3) == 274.625 |
Returns exponent value. |
RANDOM() |
RANDOM() |
Returns a random number between zero and one. This function is commonly used in A/B testing. The RANDOM() function does not accept parameters. |
ROUND(number, decimalPlaces) |
ROUND(%Friends%, 3) == 6.525 |
Rounds number to certain defined number of decimal places. |
Function Name |
Example |
Details |
|---|---|---|
AND(); |
IF((%reset%="Yes" AND( %reboot%="Yes")), "Closed", "Escalated") |
Logical operator that performs a function if all conditions are both met. |
COUNTIF(values, expression_or_value) |
COUNTIF(%MyArray%, >10) |
Returns a count of the number of repeated elements if a condition is met. |
EQUALS( Field_Name, 'Condition') |
IF( EQUALS(%Department%,'401(k)'), "Then Result", "Else Result" ) |
The EQUALS function is used when comparing a field to a particular value or another field. |
IF(EXPRESSION,THEN, ELSE) |
IF((%reset%="Yes" || %reboot%="Yes"), "Closed", "Escalated") |
If EXPRESSION evaluates to True, THEN is returned, otherwise ELSE is returned. |
OR() |
IF((%reset%="Yes" OR( %reboot%="Yes")), "Closed", "Escalated") |
|
SUMIF(values, expression_or_value) |
SUMIF(%MyArray%, >5) |
Returns the sum of all comma-separated elements and value if a condition is met. |
Function Name |
Example |
Details |
|---|---|---|
CASE(value, $CASE) |
CASE(%Name%, UPPER) == "TONY JONES" CASE(%Name%, LOWER) == "tony jones" CASE(%Name%, SENTENCE) == "Tony jones" CASE(%Name%, TITLE) == "Tony Jones" |
Changes case based on $CASE type. $CASE must be LOWER, UPPER, SENTENCE, or TITLE. |
CONCATENATE(value1, value2, ..., valueN) |
CONCATENATE(%FirstName%, " ", %LastName%) == "Tony Jones" |
Concatenates the elements/strings together into a single string. |
CONTAINS(input_string,value) |
CONTAINS(%FirstName%, "Tony") == True |
Evaluates if a value is contained within a string. |
SPLIT(text, splitToken, limit); |
SPLIT("Tony Jones", " ", 2) == "Tony", "Jones" |
|
STRING(value) |
STRING(%Friends%) == "6.5" |
Converts any value into a String. |
SUBSTRING(text, startIndex, endIndex) |
SUBSTRING("Substring!", 3, 9) == "string" |
Extracts the characters from a string between two specified indexes and returns the value. |
Function Name |
Example |
Details |
|---|---|---|
AGE(dateOfBirth) |
AGE(%Birthdate%) == 7 |
Returns an age (in years) with the given date of birth on today's date. Use the Date element. |
AGEON(dateOfBirth, futureDate) |
AGEON(%Birthdate%,"07-09-2024") == 16 |
The age of someone (in years) with the given date of birth on a future date. Use the Date element. |
DATE(value) |
DATE(%DOB%) == Wed Jul 19 1978 16:00:00 GMT-0700 (PDT) |
Use a Date element. Returns full JavaScript format. |
DATEDIFF(date1, date2) |
DATEDIFF(%DOB%,%TODAY%) == 13559 |
The difference between 2 dates in days. The value will always be a positive integer. Use the Date element. |
DAYOFMONTH(date) |
DAYOFMONTH(%TODAY%) == 2 |
Returns the day of the month. Use the Date element. |
DAYOFWEEK(date) |
DAYOFWEEK(%TODAY%) == 4 |
Returns the day of the week as an integer. Monday is 1, Sunday is 7. |
HOUR(date) |
Return the current hour according to local time. |
|
MINUTE(date) |
Return the current minute according to local time. |
|
MOMENT() |
MOMENT(%policyStartDate%).add(1, 'year').subtract(1, 'day') |
Returns the moment object of Moment.js This can be used to perform complex date formatting, calculations, manipulation, comparisons, etc. The MOMENT() function must contain parameters, for example, MOMENT(NOW()). Appending .calendar() to this function is a recommended best practice. |
MONTH(date) |
MONTH(%TODAY%) == 9 |
The month of the year as an integer. Use the Date element. |
NOW() |
NOW() == Thu Aug 27 2019 16:32:00 GMT -0700 (PDT) |
Returns current date and time in full JavaScript format. Milliseconds are always set to 0. The $Vlocity.NOW environment variable applies the user or org time zone, while the NOW() function applies UTC time. |
TODAY() |
TODAY() == Thu Aug 27 2019 00:00:00 GMT -0700 (PDT) |
Returns today's date. The time is always set to midnight |
YEAR(date) |
YEAR(%TODAY%) == 2019 |
Returns the year of the date as an integer. Use the Date element. |
Function Name |
Example |
Details |
|---|---|---|
ARRAY(value1, value2, ..., valueN) |
ARRAY(%Child1%,%Child2%, %Child3%,%Child4%) == [4,3,1,2] |
Returns an array of the value of the elements. |
AVERAGE(array) |
AVERAGE(%Age%) == 2.5 |
Aggregate: returns the average mean value of the numbers provided. Use a repeating element. |
AVERAGE(value1, value2, ..., valueN) |
AVERAGE(%Child1%,%Child2%, %Child3%,%Child4%) == 2.5 |
Returns the average mean value of the numbers provided. |
COUNT(array) |
COUNT(%Age%) == 4 |
Aggregate: Returns a count of the number of repeated elements. |
EXISTS(array_or_value, expression_or_value) |
EXISTS([%FirstName%,%LastName%], "Tony") == true |
Returns true if the given value exists in one or more elements. For Aggregate, enter the name of a repeating element—for example EXISTS(%FirstName%,"Tony"), where FirstName is repeatable. |
MAX(array) |
MAX(%AGE%) == 4 |
Aggregate: Returns the largest value in the numbers provided. Use a repeating element. |
MAX((value1, value2, ..., valueN) |
MAX(%Child1%,%Child2%, %Child3%,%Child4%) == 4 |
Returns the largest value in the group of elements provided. |
MIN(array) |
MIN(%AGE%) == 1 |
Aggregate: returns the smallest value in the numbers provided. Use a repeating element. |
MIN((value1, value2, ..., valueN) |
MIN(%Child1%,%Child2%, %Child3%,%Child4%) == 1 |
Returns the smallest value in the group of elements provided. |
SUM(array) |
SUM(%AGE%) == 10 |
Aggregate: returns the sum of all values in the repeatable element. |
SUM(value1, value2, ..., valueN) |
SUM(%Child1%,%Child2%, %Child3%,%Child4%) == 10 |
Returns the sum of all comma-separated elements and values. Note that
when you use a Formula input in an Omniscript with the SUM formula, the Expression
text box defaults the precision of decimal values to two. This occurs even if you
specify the desired number of decimal values in your formula. For instance, if you
use the formula |

