To take full advantage of Optitask it is important to understand the concept of datasets and how
they are used in tasks.
Datasets are one of the core elements in Optitask that allow actions to share data between each
other. Datasets are in-memory tables with columns and rows that hold a set of data from an
Excel Spreadsheet, a database table, a text file or any other piece information that can be
presented in tabular format.
A typical in-memory dataset will look like this:
|
ID
|
First Name
|
Last Name
|
Birth Date
|
Sex
|
|
8005
|
Erhard
|
Smit
|
1980-05-05
|
Male
|
|
8898
|
John
|
Ellis
|
1975-03-21
|
Male
|
|
7767
|
Marcy
|
Anderson
|
1956-01-03
|
Female
|
|
…
|
…
|
…
|
…
|
…
|
Some action components can return a dataset for example the SQL Task component can query a
database and return the results in a dataset like the table above. When a dataset is returned by
an action the child actions that are created under that parent action will be executed for each
record in the dataset.
Below is the structure of a typical task with actions:
This task will execute in the following order:
1. Action 1 will execute
2. Action 2 will execute, this action is a SQL Task that returns the dataset above from a
SQL
SELECT statement
1. Child Action 1 will execute (for record ID 8005)
2. Child Action 2 will execute (for record ID 8005)
3. Child Action 1 will execute (for record ID 8898)
4. Child Action 2 will execute (for record ID 8898)
5. Child Action 1 will execute (for record ID 7767)
6. Child Action 2 will execute (for record ID 7767)
3. Action 3 will execute
4. Action 4 will execute
As you can see, child actions can loop through a dataset and extract information from the
dataset from the current record in the dataset.
For a child record to access the data a dataset name must be given to the dataset that will be
populated in Action 2, for example:
The child action 1 is placed underneath Action 2 as a child action:
Child Action 1 is a Write to File component, to access the data from Action 2 you can use the
Insert Expression button to get data from the “employeeds” dataset.
Child Action 1 is now configured like this:
As you can see we can extract data directly from Action 2’s dataset by specifying the dataset
name followed by a dot and the name of the field of the dataset that we need.
By running the task the two actions will produce the following text file: