Skip to end of metadata
Go to start of metadata

Use the logical functions to control the flow of Jitterbit scripts.

NOTE:

  • The maximum number of loop iterations allowed in Jitterbit Harmony is 50,000.
  • The maximum number of loop iterations in Jitterbit Script Language is per each individual loop. To increase the allowed number of iterations per loop in a Jitterbit Script Language script, see jitterbit.scripting.while.max_iterations in Scripting Jitterbit Variables.
  • The maximum number of loop iterations in JavaScript is per script (aggregate of all loops within one script). To increase the maximum number of loop iterations in JavaScript, see Java Script Loop in JavaScript.

Case

Declaration

typeN Case(bool b1, type1 arg1[, bool b2, type2 arg2,... bool bN, typeN argN])

Syntax

Case(<b1>, <arg1>[, <b2>, <arg2>,... <bN>, <argN>])

Required Parameters

  • b1: An expression to be evaluated for its boolean result
  • arg1: An argument to be returned if b1 is true

Optional Parameters

  • b2... bN: Additional expressions to be evaluated for truthiness
  • arg2... argN: Additional arguments to be returned if the matching parameter is true

Description

This function evaluates pairs of arguments: if the evaluation of the expression in the first argument of a pair is true, it stops checking and returns the second argument with the type preserved. Otherwise it will check the next pair, and so on. If none of the pairs evaluate to truenull is returned.

To create a default or fall-through case, use true and the desired return value as the last pair. See the example.

Examples

This example returns "Very Expensive" if price is 1000 or higher. The true in the last pair of arguments serves as the default or fall-through case.

$label = Case(price < 10, "Cheap", 
              price < 100, "Not Cheap", 
              price < 1000, "Expensive", 
              true, "Very Expensive");


Equal

Declaration

bool Equal(type1 array1, type2 array2)

bool Equal(type1 arg1, type2 arg2)

Syntax

Equal(<array1>, <array2>)

Equal(<arg1>, <arg2>)

Required Parameters

  • array1, array2: (First form) Two arrays of the same length and dimension; if not, the function returns false
  • arg1, arg2: (Second form) Two simple types or expressions

Description

Performs a recursive comparison of two arrays. Returns true if all corresponding members of the arrays are equal, otherwise it returns false. It can also be used with simple types, and follows conversion rules to promote different types to compare them.

Calling this function to compare two arrays is different from using the == operator on two arrays. Using the == operator on two arrays returns an array of booleans containing the result of a comparison of each array member. Using this function compares each corresponding element in turn.

The Equal() function always returns false if the two array arguments have different sizes.

Type conversion and promotion is performed if the arguments or elements being compared are of different types.

Examples

x = {1, 2.0, 3};
y = {1, 5, 3};

// Returns false since 2.0 != 5
Equal(x, y);

// Returns true because both arrays contain only non-zero numbers.
// Comparison is made as booleans
Equal(Bool(x), y);

If

Declaration

typeN If(bool condition, type1 trueResult[, type2 falseResult])

Syntax

If(<condition>, <trueResult>[, <falseResult>])

Required Parameters

  • condition: An expression to be evaluated for its boolean result
  • trueResult: An expression to be evaluated and its result returned if condition is true

Optional Parameters

  • falseResult: An expression to be evaluated and its result returned if condition is false

Description

Returns trueResult if condition is true, else it returns falseResult.

If the first argument (condition) is not a boolean data type, it is converted to a boolean before it is evaluated. If the optional third argument is not specified and condition is false, a null value is returned.

Examples

//  Returns "Diane"
If(false, "Jack", "Diane");

// Returns "Spoon"
If(7>4, "Spoon", "Knife");

// Adds a trailing comma to s if s is not empty
If(Length(s)>0, 
    s = s + ",";
    );

While

Declaration

null While(bool condition, type expression)

Syntax

While(<condition>, <expression>)

Required Parameters

  • condition: An expression to be evaluated for its boolean result
  • expression: An expression to be evaluated repeatedly as long as condition is true

Description

Repeatedly executes an expression as long as a condition is true.

The Jitterbit variable jitterbit.scripting.while.max_iterations limits the number of iterations. An error is reported if the maximum number of iterations is reached.

Examples

$jitterbit.scripting.while.max_iterations = 2000;
i = 0;
arr = {"a@example.com", "b@example.com", "c@example.com"};
s = "";
// Concatenates the elements of the array arr 
// with commas separating each element
While(i < Length(arr),
    s = s + Get(arr,i) + ",";
    i++;
    );

Search in This Topic
On This Page

Last updated:  Feb 20, 2019