Manage Workflows Using Controller Scripts¶
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.
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"
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,arr_list); // 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") );