Use Global Table To Retrieve Data From Loop

The purpose of this Action example is to illustrate how to use a global data source to fetch data from a called action either, either through EXECUTE.ACTION or EXECUTE.ACTION.LOOP. 

This example is provided as inspiration only. It must be adapted to your Perfion environment to work. Perfion Support does not assist with such adaptations. Please contact your Perfion Partner or your Perfion consultant if you need assistance.

Sometimes when working with Action, you want to use a sub-action to enrich the product data you're working on, or perform import or exports on subsets of the data. 

In these cases, it can be advantageous to define tables in the global scope, and then populate these tables in the sub-actions. 

An importable example of the action can be found here: 

The Calling Action:

The Called Action:

Sample data for building Action Map

Data must be adapted to your Perfion enviroment to work.

The Calling Action:

Action Map - From

To

Command

Action

Script

Note

.

$Products

EXECUTE.SCRIPT

 

String tableName = P.To;
DataTable outTable = new DataSet(tableName ).Tables.Add( tableName );
outTable.Columns.Add( "_Value" );
Sources.Set(tableName , outTable );

Create a new data source and store it as "$Products".
The $-sign ensures that table will be stored in the global scope.

{ "Items": [
{"id": "559"},
{"id": "560"},
{"id": "561"}
]
}

skus_for_loop

SELECT.JSON

 

 

Using JSON to create some test data to loop through. The IDs are Perfion Item IDs

Items

@Context

 

 

 

 

id

FROM

 

 

 

In order to be able to pass data to the EXECUTE.ACTION.LOOP the input-column must be named FROM

tbl_products

tbl_products_json_wrapped

SELECT

 

 

 

skus_for_loop

 

EXECUTE.ACTION.LOOP

  1. Sub-action To Populate Global Table

 

Loop through the IDs from the previous step

The Called Action:

Action Map - From

To

Command

Action

Script

Note

 

 

EXECUTE.SCRIPT

 

var["$id"] = Sources[ P.From];

The ID of the parent action is stored in the P.To datasource.
Here we fetch it and store it is a variable

.

tbl_products

SELECT.PERFION

 

<Query>
<Select languages='EN'>
<Feature id='**' view='Config' />
</Select>
<From id='100' />
<Where>
<Clause id='ID' operator='=' value='{=$id}' />
</Where>
</Query>

Simple Perfion query to select the Product with the ID from the parent action

Table

@Format

 

 

 

 

tbl_products

$Products

JOIN

 

 

Join the result onto the global table $Products