DSL Reference
Moveworks Domain Specific Language (known as DSL for short) is a way of creating a rule to define some business logic. This language is supported by a rule engine that offers various logical operators.
Moveworks Domain Specific Language (known as DSL for short) is a way of creating a rule to define some business logic. This language is supported by a rule engine that offers various logical operators.
To know about the Data objects that you can use, please review the following Moveworks Data Objects To go through some common examples, please review the common examples.
DSL rules evaluate against Moveworks Data Objects like User, Ticket, Doc, Domain, and Ticket Context or data objects from external connectors (such as API responses in a JSON format).
All keywords in the DSL grammar are case-insensitive (i.e.: TRUE, true, TrUe, tRuE, etc all mean the same thing). Rules can contain extra spaces/tabs/newlines without impacting the execution of the rule. The only exception is for whitespace contained within quotes for string-matching.
Precedence rules (decreasing priority):
Syntax: "..." | '...'
If the text value contains quotations or an apostrophe, it can be escaped using a backslash (\\). If the text is wrapped in single quotes, then double quotes do not need to be escaped, and if the text is wrapped in double quotes then single quotes do not need to be escaped.
Examples:
Syntax: ### | -### | ###.### | -###.###
We support both integer and float values. Examples:
Syntax: NULL
Constant value which represents the lack of existence of another object or the canonical value of None
Syntax: TRUE | FALSE
Constant values which represent the canonical values of true and false.
Syntax: [expression1, expression2, ...]
Expressions can be hard-coded values or defined dynamically in terms of the input payload. Examples:
Syntax: {keyExpression1: valExpression1, keyExpression2: valExpression2, ...}
Defines a way to construct a set of key-value pairs. Note that the key types must be a primitive type (text/number/boolean/null) Examples:
Syntax: NOT ...
Converts a value to the opposite of its truth value. Examples:
Syntax: expression1 AND expression2 AND expression3 AND ...
Walks down a list of expressions and returns the first falsy value. If all expressions are truthy then the last element of the chain is returned.
Note that AND expressions are lazily evaluated. In other words if expression2 is falsy then expression3 will not be evaluated. Examples:
Syntax: expression1 OR expression2 ORAORND expression3 OR ...
Walks down a list of expressions and returns the first truthy value. If all expressions are false then the last element of the chain is returned.
Note that OR expressions are lazily evaluated. In other words if expression2 is truthy then expression3 will not be evaluated. Examples:
Syntax: .identifier
Gets attribute at identifier from parent object. identifier must be alphanumeric (underscores ok) and not start with a number. This accessor method does not work on list objects. For non-standard keys or indexing into list objects, see the section below on complex accessors.
Complex accessor
Syntax: ...[expression]
Gets attribute at expression from the parent object. Works for both objects and lists. If parent object is a list, expression is expected to evaluate to an INTEGER. If expression evalutes to a negative value it’s used to index relative to the end of the list. expression can be a simple primitive or a complicated value. Note that you can apply a complex accessor to the root payload by prefixing it with a dollar sign $. This is useful if the top-level keys in your payload do not conform to the definition of an identifier as stated above. Examples include integer keys and keys with special characters.
List range accessor
Selects all elements from a parent list / text starting at start (inclusive) and ending at end (exclusive). If start or stop is negative it is used as an index relative to the end of the list. Evaluation fails with an error if any element of the range expression is not INTEGER or NULL type. Examples:
Given Payload Response
.identifierTo access the name of the user:
Expected Result:
To get the city from the address:
Expected Result:
To access the last email of the user:
Expected Result:
To get a month using an expression:
Expected Result:
To access a value with a non-standard key:
Expected Result:
To get the first three items:
Expected Result:
To select a range of months (from March to May):
Expected Result:
To get the last three months of the year:
Expected Result:
A constant value can be denoted in DSL as:
Expected Result
When working in JSON make sure to wrap in single quotes '' with double quotes ""
The IN operator is used to determine if the left operand is contained within the right operand. This operation is versatile and can be applied to various types of data on the right side, including text, lists, and objects. The interpretation of “membership” varies depending on the data type of the right operand:
Should the right operand be of any type other than these specified, the operation will fail with an error.
Text Membership / Substring Match
Checking if a character is part of a string:
Attempting to check membership of a non-text type in a text string:
List Membership
Verifying if an element is in a list:
Checking if a list is an element of another list (which is not the case here):
Object Key Membership
Determining if a value is a key in an object (note that it checks for keys, not values):
Invalid Membership Check
Attempting to perform a membership check where the right operand is not a valid type for this operation:
These examples illustrate how the IN operator functions across different data types, providing a flexible means to check for the presence of an item within various data structures.
The IF, THEN, ELSE operators provide a way to execute conditional logic, allowing you to evaluate a condition and return different results based on whether the condition is true or false. These operators are used to control the flow of logic in expressions, enabling dynamic decision-making based on data.
TRUE or FALSE).TRUE.FALSE.The syntax can be written in a single line for simple expressions or extended with nested conditionals for more complex logic. If the condition does not evaluate to a boolean, the operation will result in an error.
Basic Conditional
Checking if a string starts with a specific prefix and returning a boolean
Conditional with Different Return Types
Returning different strings based on a condition:
Nested Conditionals
Using nested IF, THEN, ELSE statements to evaluate multiple conditions:
Invalid Condition
Attempting to use a non-boolean condition:
Complex Nested Conditional
Combining multiple conditions for more intricate logic:
These examples demonstrate how the IF, THEN, ELSE operators can be used to implement conditional logic, supporting both simple and complex decision-making processes across various data types and scenarios.
Lambdas are powerful keywords that allow you to run programming functions, significantly enhancing the expressiveness of our DSL rules. They can be called in two ways, as a regular function f(x) or a method x.f(). Functions are prefixed with a $ sign (e.g., $LOWERCASE("hElLo). Below is a catalog of the available DSL lambda functions with corresponding examples.
Description: Applies a mutator function to all values within a container (e.g., list, object), potentially transforming each item based on the mutator function provided.
Output Type: any (The type of the output will match the type of the input container, with the values mutated as specified by the operator function.)
Parameters:
any)any)Object/Dict types (Type: any)Example Usage:
Suppose you have a list of integers and you want to square each number:
Given the payload response:
To apply the MAP function to square each number:
Expected Result:
Or, if you have an object and you want to append “_modified” to each value:
Given the object:
To modify each value in the object:
Expected Result:
.method ModeSuppose you have a list of strings representing names, and you want to convert each name to uppercase:
Given the list:
To apply the MAP function in .method mode to convert each name to uppercase:
Expected Result:
key ParameterLet’s consider an example with an object where you want to append the key to each of its values:
Given the object:
To modify each value in the object by appending its key:
Expected Result:
Description: Filters items in a container (such as a list or an object) based on specified criteria. Based on a boolean(true/false) condition, the filter function determines which items should be included in the output.
Output Type: any (The type of the output matches the input container type but only includes items that meet the filter criteria.)
Parameters:
any)true) are included in the output.
any)any)Example 1: Filtering a List
Given the payload response:
To filter out all numbers greater than 2:
Expected Result:
Example 2: Filtering an Object
Given the payload response:
To filter out entries with values greater than 10:
Expected Result:
Using.method Mode
Given the payload response:
To filter out words longer than 5 characters:
Expected Result:
Using thekey Parameter
Given the payload response:
To filter out entries where the key contains “special”:
Expected Result:
Given the payload response:
To filter out entries where the key starts with “temp”:
Expected Result:
Description: Evaluates whether all elements within a given container (such as a list or an object) meet specified criteria. If an operator is not provided, a default truthy check is performed on each element.
Output Type: boolean
Parameters:
any)true if the condition is met. If omitted, a default truthy check is performed.
any)any, Default: null)Example 1: Checking a List of Numbers
Given the payload response:
To check if all numbers are greater than 0:
Expected Result:
Example 2: Checking an Object for Value Conditions
Given the payload response:
To check if all scores are above 75:
Expected Result:
.method ModeGiven the payload response:
To check if all words are non-empty:
Expected Result:
key ParameterGiven the payload response:
To check if all keys start with “key”:
Expected Result:
Description: Evaluates whether any elements within a given container (such as a list or an object) meet specified criteria. If an operator is not provided, a default truthy check is performed on each element.
Output Type: boolean
Parameters:
any)true if the condition is met for any element. If omitted, a default truthy check is performed.
any)any, Default: null)Example 1: Checking a List of Numbers
Given the payload response:
To check if any number is greater than 0:
Expected Result:
Example 2: Checking an Object for Value Conditions
Given the payload response:
To check if any score is above 75:
Expected Result:
.method ModeGiven the payload response:
To check if any word is non-empty:
Expected Result:
key ParameterGiven the payload response:
To check if any key starts with “special”:
Expected Result:
Description: The FIND operator locates the key or index of the first element in a container (such as a list or object) that satisfies a specified condition. If no condition is provided, it performs a truthy check on the elements.
Output Type: any (The output is the key or index of the first element that meets the condition, matching the type of the container’s keys or indices.)
Parameters:
any)any)Object/Dict types. (Type: any)Example Usage:
Suppose you want to find the index of the first negative number in a list:
Given the payload response:
To apply the FIND function to locate the first negative number:
Expected Result:
Or, if you have an object and want to find the key of the first value that contains “apple”:
Given the object:
To find the key of the first value containing “apple”:
Expected Result:
.method ModeSuppose you have a list of strings representing tasks, and you want to find the index of the first task that starts with “Review”:
Given the list:
To apply the FIND function in .method mode to locate the first “Review” task:
Expected Result:
key ParameterLet’s consider an example with an object where you want to find the key of the first entry whose value is exactly “banana”:
Given the object:
To find the key of the first exact “banana” value in the object:
Expected Result:
Description: The REDUCE operator processes each item in a container (e.g., list, object) with an accumulator function and an initial value to produce a single cumulative result. A common use case is calculating the sum of an array’s elements.
Output Type: any (The output is the cumulative result produced by the accumulator function.)
Parameters:
any)any)any)any)any)Example Usage:
Given Payload:
To calculate the sum of the numbers:
Expected Result:
Given Payload:
To sum each element multiplied by its index:
Expected Result:
Given Payload:
To sum the values of a dictionary:
Expected Result:
Given Payload:
To perform a conditional sum, excluding the value for key ‘f’:
Expected Result:
Description: Determines whether a given text value starts with a specified prefix.
Output Type: boolean
Parameters:
text)text)Example Usage:
Given a string, you want to check for a specific starting sequence:
To check if the filename starts with “report”:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Determines whether a given text value ends with a specified string.
Output Type: boolean
Parameters:
text)text)Example Usage:
Given a string, you want to check for a specific ending sequence:
To check if the filename ends with “.pdf”:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Searches for all occurrences of a regex pattern within a given text and returns a list of matches found.
Output Type: list of strings
Parameters:
text)text)false (case-sensitive). (Type: boolean, Default: false)Example Usage:
Given a paragraph from which you want to extract all the email addresses:
To find all email addresses within the content using a simple regex pattern:
Using Method Syntax:
Using Function Syntax:
Expected Result:
If you’re dealing with a case where the case sensitivity of the pattern is important, you can adjust the case_insensitive parameter accordingly. For example, to match words that start with “Ex” or “ex”:
Given:
To find all occurrences of words starting with “Ex” or “ex”:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Converts a given string to lowercase.
Output Type: text
Parameters:
text)Example Usage:
Given the payload response:
You can implement the LOWERCASE function in two ways:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Converts a given string to uppercase.
Output Type: text
Parameters:
text)Example Usage:
Given the payload response:
You can implement the UPPERCASE function in two ways:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Converts a given string to title case, where the first letter of each word is capitalized.
Output Type: text
Parameters:
text)Example Usage:
Given the payload response:
You can implement the TITLECASE function in two ways:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Encodes a given string in base64 format.
Output Type: text
Parameters:
text)Example Usage:
Given the payload response:
You can implement the ENCODE_BASE64 function in two ways:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Formats a currency value for a given denomination, correctly placing decimal points and adding the currency symbol as per the denomination code.
Output Type: text
Parameters:
decimal)text)Example Usage:
Given the payload response:
And you wish to format this amount as USD:
You can implement the CURRENCY_FORMAT function in two ways:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Concatenates a set of text values into a single string, optionally using a specified separator and allowing for the exclusion of empty strings.
Output Type: text
Parameters:
list of text)text, Default: '')false. (Type: boolean, Default: false)Example Usage:
Given the payload response:
To concatenate these words with a space as a separator and skipping empty strings:
Using Method Syntax:
Using Function Syntax:
Expected Result:
If you choose not to skip empty strings and use a comma as a separator:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Splits a text value into a list of text values based on a specified delimiter text.
Output Type: list of text
Parameters:
text)text)Example Usage:
Given a string that you want to split into words:
To split this sentence into a list of words using a space as the separator:
Using Method Syntax:
Using Function Syntax:
Expected Result:
If you have a string with a different separator, like commas:
Given:
To split this data into a list of fruit names using a comma as the separator:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Removes leading and trailing whitespace from a given text value.
Output Type: text
Parameters:
text)Example Usage:
Given a string with unnecessary leading and trailing spaces:
To remove these spaces and clean up the string:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Truncates a text value to a specified maximum length. If the text exceeds this length, it is cut off and ends with ”…” to indicate truncation. Optionally handles Unicode characters properly if specified.
Output Type: text
Parameters:
text)int)false (0). (Type: int, Default: false)Example Usage:
Given a long piece of text that needs to be truncated:
To truncate this quote to a maximum length of 25 characters:
Using Method Syntax:
Using Function Syntax:
Expected Result:
If handling a string with Unicode characters and wanting to ensure proper truncation:
Given:
To truncate this text to 10 characters, considering Unicode properly:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: Replaces occurrences of a pattern within a text value with a specified substitution. This function supports regular expressions (regEx) for pattern matching and can optionally perform case-insensitive replacements.
Output Type: text
Parameters:
text)text)text)false (case-sensitive). (Type: boolean, Default: false)Example Usage:
Given a text that contains some misspelled words:
To correct the spelling of “exampel” to “example”:
Using Method Syntax:
Using Function Syntax:
Expected Result:
If you want to replace “Hello” with “Hi” regardless of case sensitivity:
Given:
To replace all variations of “hello” with “Hi”, making the operation case-insensitive:
Using Method Syntax:
Using Function Syntax:
Expected Result:
Description: URL Encodes the string
Using Method Syntax:
Description: URL Decodes the string
Using Method Syntax:
Description: Gets the current time in seconds since Unix epoch (UTC).
Output Type: decimal
Parameters: None
Expected Result:
Returns the current Unix timestamp
Description: Converts a formatted time value to a UTC timestamp in seconds since Unix epoch.
Output Type: decimal
Parameters:
text)text, Default: null) Please check strftime for supported formatting strings.text, Default: null)Special Format Values
LDAP: Parse LDAP timestamp formatSECONDS: Parse Unix timestamp in seconds1. Basic Date Parsing
Expected Result:
2. Custom Format Parsing
Expected Result:
3. Timezone Handling
Expected Result:
4. Special Format - LDAP
Expected Result:
Description: Converts a UTC timestamp to a formatted time value.
Output Type: text
Parameters:
decimal)text, Default: null) Please check strftime for supported formatting strings.text, Default: null)1. Basic Formatting
Expected Result:
2. Custom Format
Expected Result:
3. Timezone Conversion
Expected Result:
Description: Adds a specified duration (years/months/days) to a Unix timestamp..
Output Type: decimal
Parameters:
decimal)int)int, Default: null)int, Default: null)1. Add Years
Expected Result:
1. Add Months
Expected Result:
1. Add Days
Expected Result:
1. Combined duration
Expected Result:
Description: Retrieves the current time as a text value, with options to format the timestamp, specify the timezone, and adjust the time with an offset.
Output Type: text
Parameters:
text, Default: null)text, Default: null)int, Default: null)Description: Converts a time value from one format to another, with options for specifying input and output formats, input and output timezones, and handling conversion errors.
Output Type: text
Parameters:
any)null, and attempts to auto-detect if not specified. (Type: text, Default: null)null. (Type: text, Default: null)text, Default: null)text, Default: null)boolean, Default: true)1. Basic Conversion with Default Formats and Timezones
Given an initial time value:
To convert this timestamp with default settings:
Expected Result:
(Note: The result remains the same since default formats and timezones are used.)
2. Specifying Input and Output Formats
To convert a time value from “MM/DD/YYYY HH:mm:ss” format to “YYYY-MM-DD” format:
Expected Result:
3. Timezone Conversion
To convert a timestamp from Eastern Standard Time (EST) to Pacific Standard Time (PST):
Expected Result:
4. Converting input to a different output
To convert a time value “MM/DD/YYYY” format to “MM-DD-YYYY” without specifying an input format
Expected Result:
Description: Converts any given value to its text (string) representation.
Output Type: text
Parameters:
any)Example Usage:
To convert a numerical value to text:
Expected Result:
Description: Converts any given value to its integer representation.
Output Type: int
Parameters:
any)Example Usage:
To convert a text value to an integer:
Expected Result:
Description: Converts any given value to its decimal (floating-point) representation.
Output Type: decimal
Parameters:
any)Example Usage:
To convert a text value to a decimal:
Expected Result:
Description: Returns the size of a string, list, or object. Returns 0 for null values. It throws an error if passed a value of any other type.
Output Type: int
Parameters:
any) - You can do a list of elements or a string in most casesExample Usage:
To get the length of a string:
Expected Result:
To get the length of a list:
Expected Result:
Description: The PARSE_JSON operator is used to parse a valid JSON-encoded string into its corresponding data structure. If the string is not properly formatted as JSON, this operation will throw an error.
Output Type: any (The output type can vary depending on the content of the JSON string, as it may represent an object, an array, a string, a number, a boolean, or null.)
Parameters:
text)Example Usage:
Given JSON String:
To parse this JSON string into an object:
Expected Result:
Given JSON String:
To parse this JSON string into an array:
Expected Result:
Given JSON String:
To parse this nested JSON string:
Expected Result:
Given Malformed JSON String:
Attempting to parse a malformed JSON string:
Expected Result:
An error will be thrown because the JSON string is not properly formatted. JSON keys and string values must be enclosed in double quotes.
Description: The STRINGIFY_JSON operator is designed to convert any value, including objects, arrays, or primitive values, into a JSON-encoded string. This operation facilitates the serialization of complex data structures into a format that can be easily transported or stored as text.
Output Type: text (The output is always a JSON-encoded string representation of the input value.)
Parameters:
any)Example Usage:
Given Object:
To convert this object into a JSON string:
Expected Result:
Given Array:
To convert this array into a JSON string:
Expected Result:
Given Values: A string "Hello World", a number 123, and a boolean true.
To convert these values into JSON strings:
Expected Results:
For the string:
For the number:
For the boolean:
Given Nested Object:
To convert this nested object into a JSON string:
Expected Result:
Description: Evaluates whether two lists contain exactly the same elements in any order. This function is useful for comparing lists where the sequence of elements is not important, but their presence is. It checks for equality of contents without considering the order of the items.
Output Type: boolean
Parameters:
list, Item Type: any)list, Item Type: any)1. Comparing Lists with Identical Contents
Given two lists:
To check if these lists have identical contents:
Expected Result:
This result indicates that the two lists contain the same elements, regardless of their order.
2. Comparing Lists with Different Contents
Given two lists:
To check if these lists have identical contents:
Expected Result:
This result indicates that the two lists do not contain the same set of elements.
3. Comparing Lists with Different Lengths
Given two lists:
To check if these lists have identical contents:
Expected Result:
This result indicates that the lists do not have the same contents, as their lengths are different.
4. Comparing Lists with Repeated Elements
Given two lists with repeated elements:
To check if these lists have identical contents:
Expected Result:
This result indicates that the two lists contain the same elements, including the correct count of repeated elements, regardless of their order.