Source Expression Language
Boolean expressions
Boolean expressions yield a value of true or false. They are used to dynamically set the value for Yes/No flags such as the Required flag on a question. A Boolean expression may be a comparison such as = or >, a Boolean function such as Intersects, or a logical operation such as “and” or “not” on another Boolean expression.
Value expressions
Value expressions yield values such as strings, numbers, dates, or Boolean values. They are used to set answer values such as defaults and calculations.
Language Elements
Answer keys
Answer keys must be delimited with angle brackets < >. Dotted answer keys give access to subparts of complex answer types. For example, if <A> has an object value then <A.prop> yields property prop of that object. Similarly if <B> is an array then <B.0> is the first element of that array.
Operators
Literals
String Literals
-
Plain String Literals: These are indicated by double quotes. For example,
"Hello, world!"
. -
Localizable Strings: Should be enclosed in single quotes. These are considered "magic strings" and can include interpolated values. An example is
'Hello, <Entity_Name>!'
. (Not available in Transformations). -
Escape Characters: The backslash (
\
) serves as an escape character, allowing the inclusion of quotes within the string literals. To include a single or double quote within a string, precede it with a backslash. For instance,"He said, \"Hello!\""
. -
Escaping Backslashes: To include a backslash itself in the string, it must be doubled. For example, to represent a single backslash in a string, use
"\\"
.
Number Literals
Number literals are represented with a plain number or float value.
Example: 1
and 3.14
will return their own value.
Array Literals
To define an array literal, wrap a collection of expressions in square brackets []
.
Example: ["hello", 12, 1 > 2, concat("hello", "world")]
would return ["hello", 12, false, "hello world"]
Object Literal
- Static Keys: All object literals must be defined with static keys. Expression evaluation for keys is not valid syntax.
- Dynamic Values: The value for a given key must be a valid source expression.
Example: {"hello": "world", "nine": 9, nested: {"key": "value"}, "arr": ["test", "array"], "func": concat("hello", "world")}\
Operators
Operator | Description |
---|---|
= | Case-Insensitive Equality Operator: Returns true if both operands are equal, ignoring case differences. Example: "foo" = "FOO" returns true; "foo" = "foo" also returns true. |
== | Case-Sensitive Equality Operator: Returns true if both operands are exactly equal, including case. Example: "foo" == "FOO" returns false; "foo" == "foo" returns true. |
!= or <> | Case-Insensitive Inequality Operator: Returns true if operands are not equal, ignoring case differences. Example: "foo" != "bar" returns true; "foo" != "FOO" returns false. |
!== | Case-Sensitive Inequality Operator: Returns true if operands are not equal, considering case differences. Example: "foo" !== "bar" returns true; "foo" !== "FOO" also returns true. |
> | Greater Than Operator: Returns true if the first operand is greater than the second operand. Example: 1 > 2 returns false; 3 > 2 returns true. |
>= | Greater Than or Equal To Operator: Returns true if the first operand is greater than or equal to the second operand. Example: 1 >= 2 returns false; 2 >= 2 returns true; 3 >= 2 returns true. |
< | Less Than Operator: Returns true if the first operand is less than the second operand. Example: 3 < 2 returns false; 1 < 2 returns true. |
<= | Less Than or Equal To Operator: Returns true if the first operand is less than or equal to the second operand. Example: 3 <= 2 returns false; 2 <= 2 returns true; 1 <= 2 returns true. |
and | Binary AND Operator: Returns true if both Boolean values are true. Example: true and true returns true; true and false returns false. |
in | Membership Operator: Returns true if a value exists within an array. Example: "a" in ["a", "b", "c"] returns true. |
not | Logical Negation Operator: Returns true if the following expression is false. Example: not true returns false; not false returns true. |
or | Binary OR Operator: Returns true if at least one of the Boolean values is true. Example: true or false returns true; false or false returns false. |
Functions
Function | Description |
---|---|
AddDays(date, days) | Add a number of whole or fractional days to a date. The date parameter will be coerced to a date on a best-effort basis, but ISO-8601 format is known to be reliable. |
AddMinutes(date, minutes) | Add a number of whole or fractional minutes to a date. The date parameter will be coerced to a date on a best-effort basis, but ISO-8601 format is known to be reliable. |
All(groupKey) | Return an array of instance IDs in the group identified by groupKey. Note: The parameter is evaluated to get the key, so you would use All(“My_Group”) , not All(\<My_Group>) . |
ArrayAll(array, expression) | Returns true if the expression is true for each array element. The special key <arg0> should be used in the expression to represent the array element. e.g., ArrayAll(<My_Array>, <arg0> > 10) would be true if every element of the array is greater than 10. Passing an empty array will always return true. |
ArrayAny(array, expression) | Returns true if the expression is true for at least one array element. The special key <__arg0> should be used in the expression to represent the array element. e.g., ArrayAny(<My_Array>, <arg0> > 10) would be true if any element of the array is greater than 10. Passing an empty array will always return false.Example: ArrayAny([1, 2, 3, 100], <__arg0> < 50) would return true |
ArrayMap(array, expression) | ArrayMap would let you do ArrayMap([1, 2, 3, 4], <__arg0> * <__arg0>) to get [1, 4, 9, 16] |
ArrayFilter(array, expression) | You can write ArrayFilter(<Array1>, <__arg0> not in <Array2>) to get the elements of Array1 that are not in Array2. |
ArrayUnique(arr, by?) | Returns a copy of arr removing duplicate values in the same order. The optional by parameter removes duplicate objects from the array if the key specified by the parameter is the same. The left-most object will be returned.ArrayUnique([1, 1, 2, 2, 4, 3, 3, 4]) returns [1, 2, 4, 3] ArrayUnique([{"a": 1}, {"a": 2}, {"a": 1}, {"b": 1}], "a") returns [{"a": 1}, {"a": 2}, {"b": 1}] |
Compact(array) | Removes nulls from an array |
Concat(...strings) | Takes multiple variadic string arguments and concatenates the strings together.Concat("hello", "world") returns "hello world" |
ConcatArray(...arrays) | Takes multiple variadic array arguments and concatenates the arrays together.ConcatArray([1, 2],[3, 4]) returns [1, 2, 3, 4] |
Count(input) Len(input) Length(input) | Returns the count based on the datatype of the input - string: Number of characters in the string - array: Number of elements in the array |
EnsureArray(input) | Make sure the provided argument is an array. If not, wrap the value in an array. |
GroupInstance(groupKey, filter?) | Return the first instance id of the provided group key that matches the given filter, if provided.GroupInstance("ERP_Record", <ERP_ID> > 123) |
GroupInstanceReversed(groupKey, filter?) | Return the first instance id of the provided group key that matches the given filter, if provided.GroupInstanceReversed("ERP_Record", <ERP_ID> > 123) |
GroupInstances(groupKey, filter?) | Return the first instance id of the provided group key that matches the given filter, if provided.GroupInstances("ERP_Record", <ERP_ID> > 123) |
Join(array, delimiter) | Returns the given array as a string, separated by the delimiterJoin(["hello", "world"], " ") returns "hello world" |
Match(string, regex) | Determines if the specified regex successfully matches the entire string, returning true if it does and false otherwise. |
MatchAny(array, regex) | Determines if the specified regex successfully matches any of the strings in the provided array, returning true if it does and false otherwise. |
PhoneNumberBase(phoneNumber) | Returns a phone number without any additional information such as extension or country code.PhoneNumberBase("+1 333-444-5555 ext 123") returns "333-444-5555" |
PhoneNumberCountry(phoneNumber) | Returns the country based on the phone number's country code prefix. Defaults to US for vendors who not have a country code on their phone number.PhoneNumberCountry("+1 333-444-5555 ext 123") returns "US" |
PhoneNumberCountryCode(phoneNumber) | Returns the country based on the phone number's country code prefix. Defaults to 1 for vendors who not have a country code on their phone number.PhoneNumberCountry("+1 333-444-5555 ext 123") returns 1 |
Pick(array, index) | Gets the element in the array at the second argument's index (0 indexed)Pick([1, 2, 3, 4], 2) returns 3 |
Replace(string, regex, replacement, flags) | Modifies a given string by substituting parts of the string that match a specified regular expression pattern with a replacement string. The flags argument can be used to specify additional options for the regex operation, such as case insensitivity or global replacement, influencing how the matching and replacement are performed. Replace("hello world", "^hello", "hi", "g") returns "hi world" |
RoundTo(value, decimalPlaces) | Rounds the provided value to a provided number of decimal places |
Strip | Removes all matching patterns from a string.Strip("12-34-56", "-") returns "123456" |
ToLower(inputStr) | Converts a string to all lowercase charactersToLower("This Is A STRING") returns "this is a string" |
ToUpper(inputStr) | Coverts a string to all uppercase charactersToUpper("This Is A STRING") returns "THIS IS A STRING" |
UrlEncode(url) | Converts a given string into its URL encoded equivalentUrlEncode("http://google.com/search?q=How To Do Source Expressions?") returns "https://www.google.com/search?q=how+to+do+source+expressions%253F" |
Substring(input, start, end?) | Returns the provided string starting at the second argument's index (inclusive and 0 indexed) and ending at the third argument's index (non-includive and 0 indexed). |
Unaccent(input) | Modifies the given string by replacing characters diacritical marks with the English equivalent.Unaccent("Héllo Wörld") returns "Hello World" |
Keys(obj) | Returns all of the keys in an object as an array.Keys({"a": 1, "b": 2, "c": 3}) return ["a", "b", "c"] |
Updated 3 months ago