search cancel

Steps to create a process that will read lines in a text file and pass each line separately to other operators


Article ID: 49376


Updated On:


CA Workload Automation AE - Business Agents (AutoSys) CA Workload Automation AE - Scheduler (AutoSys) Workload Automation Agent CA Process Automation Base



This tech doc will walk through the creation of a process to read lines of text from a text file and then pass those lines of text individually to other operators in the process. In this example the text file contained server names. We may want to perform some operation on each of the servers listed in this file.


Start with the "Read From File" operator and make sure that is configured correctly. For this example there is a file called test.txt located on the C drive of the ITPAM orchestrator. Place the value of the file name in the "Source File Name" parameter of the Read_From_File Operator as follows:

<Please see attached file for image>

Figure 1

Check the "Return file contents in a string array" to force ITPAM to separate out the lines in the text file for you. Fill out the working directory, user id and password for the machine containing the test.txt file (the orchestrator machine) as follows:

<Please see attached file for image>

Figure 2

Save this process and run it. Right click on the Read_from_File operator and select "Dataset". Then click on the Operation Results. You will see the following. Notice the DatasetVariable has the 3 lines from the text file in an array.

<Please see attached file for image>

Figure 3

So at this point we could reference the lines of the file with the following variable references:


But in this example we want to reference each of these server names later in an operator. To do this, we will create a loop that will reference a different line of the file for each run of the loop and therefore a different servername.

We start by defining two dataset variables or parameters. The first will be i which will be our server counter, and the second will be current_servername so that in this example we can see what the current servername is in each loop run.

<Please see attached file for image>

Figure 4

In the post-execution for the Read_From_File operator we will use the following code:


The first line defines a variable called "line_count" that is set to the length of the results from the Read_from_File operator. This is the same as the number of lines in the text file. The second line initializes the i parameter to be 0.

Then we will add a loop operator and 2 calculation operators inside the loop. The loop parameter "Repeat Count" will be set to the Process.line_count which we set above in the Read_from_File_1 post-execution.

<Please see attached file for image>

Figure 5

So now the process should look like this:

<Please see attached file for image>

Figure 6

So now to set the source code for each of the calculation operators inside the loop.

For the first calculation operator which is now named "Set_Current_Servername", we will use the following source code:


So we are giving the process variable "current_servername" the value of the first line from the file or the first item in the result array. Notice the i variable is used here so that each time the i variable changes, so will the server name.

For the second calculation operator which is now named "Increase_loop_counter", we will use the following source code:


This simply increases the i variable by 1.

And finally for demonstration purposes, we will set a breakpoint on the "Increase_loop _counter". To do that, click on the "Increase_loop_counter" operator and then click on the hand icon in the toolbar. You should now see the hand next to your "Increase_loop_counter" operator as follows:

<Please see attached file for image>

Figure 7

Now we will run the process. The first 2 operators should run and then when it hits the breakpoint it should stop. So it will look like this:

<Please see attached file for image>

Figure 8

Now, take a look at the dataset.

<Please see attached file for image>

Figure 9

You can see that the i parameter has been initialized to 0, the line_count returned 3 and the current_servername was set to the first item in the array.

Now, back on the Main Editor tab, click the Resume Process button in the toolbar.

<Please see attached file for image>

Figure 10

The process will run and stop again at the breakpoint. Take a look at the dataset again:

<Please see attached file for image>

Figure 11

Notice the current_servername has changed to the second line in the file.

You can resume the process again and see the 3rd servername appear. Then resume again and the loop will complete because the line_count has been reached.

So in a real world example you would not use the breakpoint and the calculation operator called "Set_Current_Servername" might be replaced with and operator to get the disk space back from this server. So one run of this process would return disk space from each server in the text file.


Release: ITPASA99000-3.1-Process Automation-Add On License for-CA Server Automation


1558712287967000049376_sktwi1f5rjvs16sk3.gif get_app
1558712285986000049376_sktwi1f5rjvs16sk2.gif get_app
1558712284143000049376_sktwi1f5rjvs16sk1.gif get_app
1558712281449000049376_sktwi1f5rjvs16sk0.gif get_app
1558712279643000049376_sktwi1f5rjvs16sjz.gif get_app
1558712277573000049376_sktwi1f5rjvs16sjy.gif get_app
1558712275749000049376_sktwi1f5rjvs16sjx.gif get_app
1558712273512000049376_sktwi1f5rjvs16sjw.gif get_app
1558712271788000049376_sktwi1f5rjvs16sjv.gif get_app
1558712269930000049376_sktwi1f5rjvs16sju.gif get_app
1558712265784000049376_sktwi1f5rjvs16sjt.gif get_app