Gateway Statements

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

These include:

Statement

Description

Example

abort

Stops a job and marks it as Failed with a message provided in the formula. You can use this statement to test for a specific scenario and if found, stop the job from processing.

Syntax: abort "<message to show why job is being aborted>";

abort "Invalid project ID.";

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.

attribute

Determines what action to take on a row of data. Valid actions to execute include: create or update.

Syntax: setAttribute("action", "<action to execute>");

setAttribute("action", "create");

Child Object

Finds a child object of an object (Code/UDF) based on an object and used in the formula.

Note: Use this statement to only find an object. You cannot create a new object.

Object childObj = <Parent ObjectName variable>.findOneChild (variable -> variable.fieldname

functiontoperform variable.fieldname);

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.

 

 

Field

Use a field within a formula after it has been removed by the Compare Step.

Note: To use this option if the field will be removed, place the Custom Step after Compare and before the Convert to Destination Format step.

 

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", "parameter provider"] = "parameterValue";

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

Parameter["parameter name", "Primavera Cloud"] = "parameterValue";

string someVar = Parameter["SomeParameter"];

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

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

 



Legal Notices | Your Privacy Rights
Copyright © 2019, 2022

Last Published Thursday, August 25, 2022