Supported Data Types, Operators, and Statements

Gateway supports several data types, operators, and statements. Refer to the sections below for more information on Gateway supported data types and programming constructs.

Supported Data Types

The following table lists Gateway data types supported in Primavera Gateway.

Supported Data Type

Example

Note

Boolean

Bool = true;

OtherBool = false;

Boolean values can be set as either true or false.

Date

Date DateExample = 1987-12-20T04:04:30

The Date must be in the ISO format yyyy-mm-ddThh:mm:ss.

No other formats are allowed.

Double

double example1 = 5.5;

double example2 -3.4;

double example3 = 3;

 

Integer

int z = 4 + 5.5

Assignment expressions in math such as / or * that have double values as part of the expression will truncate the decimal.

In the example, int z = 9

Object reference

<Resource> res = new <Resource>;

<Resource> res2 = null;

<Resource> res3 = <Resource>.findOne(r → 2 == 2);

References to all the fields of the object are included by default once you declare an object variable.

null

Note: You can set a variable of any data type to null, but you cannot create a null type variable.

int i1 = null;

double i2 = null;

Date i3 = null;

<Resource> myResource = null;

myResource.ObjectId = null;

 

String

String sample = "Hello World"

 

Operators

Gateway scripting language provides operators for computation and comparison. Operators can only be applied to data types they support. The following tables list operators supported in Gateway code.

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

2 + 5; //returns 7

-

Subtraction

Subtracts two Double values.

Double

Double

5 - 3; //returns 2

*

Multiplication

Multiplies two Double values.

Double

Double

2 * 5; //returns 10

/

Division

Divides two Double values.

Double

Double

10 / 2; //returns 5

3 / 2; //returns 1.5

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

true || false;

//returns true

&&

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

true && false;

//returns false

!

NOT or Inversion

Negates the specified Boolean value. Applying the NOT operator to an expression that evaluates to true will return false.

Boolean

Boolean

!true;

//returns false

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

1.0 == 1.0;
//returns true

1.0 == 2.3
//returns false

"Hello" == "Hello" //returns true

 

 

!=

Does Not Equal

Tests if two values are not equal.

All

Boolean

2 + 2 != 5;
//returns true

2 + 2 != 4;
//returns false

"Hello" != "Goodbye" //returns true

 

 

>

Greater Than

Tests if one value is greater than another.

All

Boolean

50 > 100; //returns false

50 > 5; //returns true

"2" > "10" //returns true

"Hello" > "World" //returns false

5 > "4" //error. The types of compared values must match.

 

 

>=

Greater Than or Equal To

Tests if one value is greater than or equal to another

All

Boolean

60 >= 50; //returns true

60 >= 70 //returns false

60 >= 60 //returns true

"Hello" >= "World" //returns false

 

 

<

Less Than

Tests if one value is less than another.

All

Boolean

50 < 100; //returns true

50 < 40 //returns false

"2"< "10" // returns false

"Hello" < "World" //returns true

"3/1/17" < new Date() //error the types of compared values must match

 

 

<=

Less Than or Equal To

Tests if one value is less than or equal to another.

All

Boolean

60 <= 50; //returns false

60 <= 90 // returns true

60 <= 60 //returns true

"10" <= "2" //returns true

 

Supported Special Operators

Use special operators to create structure in your Gateway code and specify how Primavera 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

"Hello" + " World" //returns "Hello World"

"Lucky Number " + 7; //returns "Lucky Number 7"

"a" + 1 + 2 //returns "a12"

5 + "Hello"; //returns an error. To perform concatenation, the leftmost operand must be a String.

=

Assignment

Assigns a value of a supported data type to a variable.

All

def myVar = 50;

Supported Gateway Statements

Gateway supports a variety of statements you can use to determine the control flow of Gateway code. The following tables list Gateway statements.

Statement

Description

Example

add

Adds an object to the synchronization.

Objects that are added will be sent to the destination.

add myResource;

//Adds the myResource variable with all associated fields to the synchronization.

delete

Removes objects and fields from the synchronization.

Objects and fields that are removed, will not be sent to the destination.

Note: Does not necessarily remove the object from the destination application.

//removes all resource objects

delete <Resource>;

//removes a single resource object

delete myResoure;

//removes the Id field

delete myResource.Id;

 

 

{ } (block)

Specifies a sequence of expressions to evaluate. Used to structure Gateway 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.

def a = 8;

{

def b = 10;

}

return a + b; // error. B is not defined within scope.

 

 

for loop

Iterates over the objects of a specific type in Gateway.

//Iterates over all of the resource objects to find a resource rate that exists for the given resource and date. If no ResourceRate is found, a new one will be created. At the end, all resource objects are removed.

for (resource: <Resource>) {

<ResourceRate> resRate = <ResourceRate>.findOne(rr2 -> (rr2.ResourceObjectId == resource.ObjectId) && (rr2.EffectiveDate == 2019-12-20T00:00:00));

if (resRate == null) {

<ResourceRate> rr = new <ResourceRate>;

rr.ObjectId = -100;

rr.EffectiveDate = 2019-12-20T00:00:00;

rr.ResourceObjectId = resource.ObjectId;

rr.PricePerUnit = 5;

add rr;

}

}

 

//remove all resource objects

delete <Resource>;

 

 

find one

Returns an object when the given condition is met.

<Resource> myRes = null;

myRes = <Resource>.findOne( r → r. Id == "My Resource" );

//Sets the myRes variable to the first resource that matches the given condition. If no resource is found to match the condition, myRes variable will be set to null.

 

 

if

Code contained in an if block will only be evaluated if the condition specified by the if statement evaluates to true.

if (1 + 1 == 2) {

//block executed if condition is true

return "True";

 

 

if/else

Code contained in an if block will only be evaluated if the condition specified by the if statement evaluates to true.

If the specified condition evaluates to false, code in the else block will be evaluated.

if (1 + 1 == 2) {

//block executed if condition is true

return "True";

} else {

//block executed if condition is false

return "Not true!";

}

 

 

if/else if

Code contained in an if block will only be evaluated if the condition specified by the if statement evaluates to true.

If the specified condition evaluates to false, code in the if else block will be evaluated.

If the specified condition evaluates to false in the if else block, then the next block of if else code will be evaluated.

Note: Any number of if else blocks can be specified.

if (1 + 1 < 2) {

//block executed if condition is true

return "True";

} else if {

//block executed if condition is false

return "Not true!";

} else if {

//block executed if condition is false

return "Equal";

 

 

new

Creates an empty object.

<Resource> myResource = new <Resource>;

//Creates an empty resource object and assigns it to myResource variable. At this point the myResource variable is not null but it has not been added to the synchronization and will not be sent.

 

 

parameter

Creates a parameter using the following syntax:

Parameter["parameter name"] = "parameterValue";

Parameter["SomeParameter"] = "someValue";

Parameter["parameter name"] = "parameterValue";

string someVar = Parameter["SomeParameter"];

Parameter["SomeParameter", "Unifier"] = "someValue";

string someVar = Parameter["SomeParameter", "Unifier"];

 



Legal Notices | Your Privacy Rights
Copyright © 2019 2021

Last Published Wednesday, January 27, 2021