Groovy is a lightweight scripting language optimized for security and performance within Primavera Gateway. Groovy syntax includes additional syntax for working with PEL (Primavera Cloud expression language).
Groovy supports several data types, operators, and statements. Refer to the sections below for more information on Groovy supported data types and programming constructs.
Supported Data Types
The following table lists Groovy data types supported in Gateway.
Supported Data Type | Example |
---|---|
Boolean |
|
Date |
|
Double |
|
String |
|
Operators
Groovy provides operators for computation and comparison. Operators can only be applied to data types they support. The following tables list Groovy supported operators in Gateway.
- Supported Numeric Operators
- Supported Logical Operators
Supported Numeric Operators
Use numeric operators to perform calculations on numeric data types, such as doubles.
Operator | Name | Description | Applicable Data Types | Return Data Type | Example |
---|---|---|---|---|---|
+ | Addition | Sums two Double values. | Double | Double |
|
- | Subtraction | Subtracts two Double values. | Double | Double |
|
* | Multiplication | Multiplies two Double values. | Double | Double |
|
/ | Division | Divides two Double values. | Double | Double |
|
% | Modulo (remainder) | Returns the remainder resulting from the division of two Doubles. | Double | Double |
|
** | Exponential | Returns the result of raising one Double to the power of another. | Double | Double |
|
Unary - | Unary Minus | Indicates a negative value | Double | Double |
|
Supported Logical Operators
Supported logical operators to manipulate and combine Boolean values and to construct conditional statements.
Operator | Name | Description | Applicable Data Types | Return Data Type | Example |
---|---|---|---|---|---|
|| | OR | Returns the result of combining Boolean values using a logical OR. If one value or expression contained in the OR statement evaluates to true, the OR expression returns true. | Boolean | Boolean |
|
&& | AND | Returns the result of combining Boolean values using a logical AND. If both values or expressions in the AND statement evaluate to true, the AND expression returns true. | Boolean | Boolean |
|
! | NOT | Negates the specified Boolean value. Applying the NOT operator to an expression that evaluates to true will return false. | Boolean | Boolean |
|
Supported Comparison Operators
Use comparison operators to measure values against each other. The data types of compared values must match, otherwise the application will return an error. The result of a comparison operation is a Boolean, true or false.
Operator | Name | Description | Applicable Data Types | Return Data Type | Example |
---|---|---|---|---|---|
== | Equal | Tests if two values are equal. | All | Boolean |
|
!= | Does Not Equal | Tests if two values are not equal. | All | Boolean |
|
> | Greater Than | Tests if one value is greater than another. | All | Boolean |
|
>= | Greater Than or Equal To | Tests if one value is greater than or equal to another | All | Boolean |
|
< | Less Than | Tests if one value is less than another. | All | Boolean |
|
| Less Than or Equal To | Tests if one value is less than or equal to another. | All | Boolean |
|
Supported Special Operators
Use special operators to create structure in your Groovy code and specify how Gateway should interpret and execute the expressions.
Operator | Name | Description | Applicable Data Types | Example |
---|---|---|---|---|
+ | Concatenation | Combines a String with another data type, yielding a new String. String concatenation is applied when the leftmost operand of the + operator is of the data type String. The right operand can be a value of any type. When concatenated, Date values may not serialize in the format anticipated. | String |
|
= | Assignment | Assigns a value of a supported data type to a variable. | All |
|
( ) | Parentheses | Specifies logical grouping and evaluation order. Statements in parentheses have increased precedence. | All |
|
new | Constructor | Instantiates a new instance of a class, resulting in an object of that class. | Date |
|
// | Comment | Indicates a single-line comment. Commented lines are not evaluated. Use comments to describe and annotate your formula script. Comments extend to the end of a line. | All |
|
/**/ | Multi-line Comment | Indicates an extended comment. Multi-line comments are not evaluated. Multi-line comments may span multiple lines. | All |
|
Supported Groovy Statements
Groovy supports a variety of statements you can use to determine the control flow of Groovy code. The following tables list Groovy statements.
Statement | Description | Example |
---|---|---|
def | Specifies a variable. Variables in Groovy are strongly typed and restricted to the data type of their initial assignment. Variables are not accessible outside the scope of the code block they are declared in. Variables declared outside of code blocks or other control structures are global and may be accessed from anywhere within the script. |
|
return | Specifies a value that should be returned as the result of a script and serve as the default value of the configured field associated with the formula script. The return statement ends script execution. If no return statement is specified, Groovy scripts automatically return the last statement evaluated. |
|
{ } (block) | Specifies a sequence of expressions to evaluate. Used to structure Groovy scripts, establish variable scope, and improve readability. Variables defined and assigned values within a code block are accessible only within the code block and other structures the code block contains. |
|
if/else | Code contained in an if block will only be evaluated if the condition specified by the if statement evaluates to true. Code in the else block will be evaluated if the specified condition evaluates to false. |
|
Unsupported Programming Constructs
For improved efficiency and security, the following Groovy programming constructs are not supported in Gateway:
- Loops (for example: for, for each)
Note: Only while loop is supported in Gateway
- Function or method definition.
- Arrays, hashes, or collections.
- Mixed assignment operators (for example: ++, --, +=, -=).
- String interpolation.
- Regular expressions.
Note: The application generates a validation error if your Groovy scripts contain unsupported data types or other unsupported control structures.