Manage workflows using controller scripts in Jitterbit Integration Studio
Introduction
A controller script is a script that contains orchestration logic to manage how and when an operation should run, and is recommended for complex workflows. It usually is the first operation of an operation chain.
Example
In this example, we want to read a list of high schools, iterate over the list, build a dictionary, and then call an update operation.
The dataset is a list of codes and high school names formatted like this:
"001,Amon Carter-Riverside HS|002,Arlington Heights HS|003,South Hills HS|4,Diamond Hill-Jarvis HS|005,Paul Laurence Dunbar HS|006,Eastern Hills HS|008,North Side HS|009,Polytechnic HS"
Note
- Using
If
in combination withRunOperation
andGetLastError
can be used so that if the operation has a technical failure, an error will be raised and the process will stop. Otherwise the operation will run normally. While
should be used for looping.
Here is a high-level example with comments:
If(!RunOperation("<TAG>operation:read_data</TAG>"),GetLastError()); // The output is written to a global variable endpoint $io
If(Length($io) > 0, // Checking if any data was read, skip if no data was generated
$dict_highschool_list = Dict(); // Initializing the dictionary
arr = Array(); // Initializing the array
arr_list = Array();
arr = Split($io,"|"); // A "|" is the record separator
cnt = Length(arr); i = 0;
While(i < cnt,
arr_list = Split(arr[i],","); // Another split to separate by commas
AddToDict($dict_highschool_list, arr_list[0],arr_list[1]);
// The dictionary key is the code, its value is the name of the high school. Note the use of brackets to denote the position in the array.
i++);
WriteToOperationLog("Number of high schools read: " + cnt);
If(!RunOperation("<TAG>operation:read_data</TAG>"),GetLastError()); // Use the dictionary as a cross-reference
,
WriteToOperationLog("No data read; stopping process")
);