Working with Text Files

Caution
Test the script(s), processes and/or data file(s) thoroughly in a test environment, and customize them to meet the requirements of your organization before attempting to use it in a production capacity.  (See the legal notice here)

 

Note: The workflow sample mentioned in this article can be downloaded from the Opalis project on CodePlex:  https://opalis.codeplex.com

 

Overview

A Workflow that demonstrates the use of several text related Workflow Activities

 

Getting Started

Launch the Workflow named ‘0.Setup’ by using Start or by running it using the Testing Console.

The Workflow will create a sample input.txt file on your C: drive. The sample input.txt file will be used by the other Workflows and has following content:

1
2
3
4

Example Workflow

1. Read from txt File

image

This Workflow uses the Custom Start Activity to obtain input data using a parameter:

image

  • Branch (1, 2 or 3): enter either 1, 2 or 3

The provided value is evaluated so that the Workflow branches accordingly. This is accomplished by using Link Conditions that are configured in the Link properties:

image

Branch 1

The Read Line Activity reads all lines from the sample text file ‘input.txt’:

image

The Send Platform Event Activity is used to display the resulting output:

image

For each line that is read by the Read Line Activity a corresponding Event is sent by the Send Platform Event.

Branch 2

The Get Lines Activity reads all lines from the sample text file ‘input.txt’. Instead of returning the read lines one by one, it returns the read lines all at once:

image

The Send Platform Event Activity is used to display the resulting output:

image

The Activity will send one Event containing all the lines read by the Get Lines Activity.

Branch 3

The Find Text Activity is used to search the sample text file ‘input.txt’ using a regular expression:

image

The regular expression ‘.*[^r^n]’ reads all characters but excludes ‘carriage return’ and ‘new line’ control characters. In this example, the regular expression will return the contents of all four lines.

The Send Platform Event Activity is used to display the resulting output:

image

The Activity will send four Events containing the result from the regular expression used in the Find Text Activity.

 

Running the example Workflow

Launch the Workflow by starting it from the Operator Console or by running it using the Testing Console. When prompted, enter the appropriate value:

image

Check the Operator Console Event screen or the Workflow Testing Console log to see the resulting output.

 

More Information

Refer to the Online Help for the Read line, Get Lines and Find Text Activities.

 

Share this post :