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

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

Optional Parameters

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

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

Optional Parameters

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

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++;
    );