Use action.trigger ()
Sometimes, you will need to handle the result of another action or execute some actions in bulk. In these cases, you can use action.trigger(), which returns Promise and allows you to reuse the result of other actions.
Let’s check a couple of cases, where action.trigger comes in handy.

Bulk actions

Getting data for a certain record

Let’s review the case when you need to combine the data from several tables about a certain record. For the example, we will use MySQL data source and two tables: Orders and Orders details. Follow the steps below:
  1. 1.
    Add a new action - Load Table. Select Order Details table as a resource. Make sure the action is titled as loadOrderDetails.
  2. 2.
    Configure selected record field as Order Number ={{data}}.
3. Next up, add another action - Load Row. Select Orders table as a resource. Make sure the action is titled as loadOrder.
4. Configure selected record field as Order Number ={{data}}.
5. Now, to combine the data from both the actions, add a new action - Code. Rename it to loadDetails and specify the code:
1
const orderId = {{data}};
2
3
const [orderData, orderDetails] = await Promise.all([{{ actions.loadOrder.trigger(orderId) }}, {{ actions.loadOrderDetails.trigger(orderId) }}]);
4
5
return {
6
...orderData,
7
details: orderDetails,
8
detailsNames: orderDetails.map(item => item.productCode),
9
detailsAmount: orderDetails ? orderDetails.length : 0,
10
};
Copied!
To display the obtained data, find a Details component and drag it onto the canvas. Assign the loadDetails action to the Details component.
Please note that you'll need to unhide the details Amount and detail Names fields to make them visible, as well as change detail Names field's view type to Multiselect/Tag for a better representation.

Getting data for all records

In case you need to see the combined data for all the records in the Table, follow these steps:
  1. 1.
    Add a new action loadOrderDetails - Load Table. Select Order Details table as a resource.
  2. 2.
    Configure selected record field as Order Number ={{data}}
  3. 3.
    Add a new Workflow: load Orders table as a first step. For testing purposes, we recommend setting the limit to 10 records.
  4. 4.
    Add a Code step with the below code as a second step:
1
async function applyDetailsToOrder(order) {
2
const orderDetails = await {{ actions.loadOrderDetails.trigger(order.orderNumber) }};
3
return {
4
...order,
5
details: orderDetails,
6
detailsNames: orderDetails.map(item => item.productCode),
7
detailsAmount: orderDetails ? orderDetails.length : 0,
8
};
9
}
10
11
const result = {{ data }}.map(item => applyDetailsToOrder(item));
12
return Promise.all(result);
Copied!
After that, add a Table and assign the applyDetailsToOrder action to it to retrieve the data.
Please note that you'll need to unhide the details Amount and detail Names fields to make them visible, as well as change detail Names field's view type to Multiselect/Tag for a better representation.

Getting certain items from the Table

Say you have a table with lots of records, but just need to display certain items. Let’s check how this can be done on an example of an HTTP API data source.
  1. 1.
    Add a new action getUser - HTTP request. Select the data source, set GET method, specify the URL as {{data}}
  2. 2.
    Add the next action getUsers - Code. Specify the below code:
1
const usersToGet = [1, 10, 2, 5, 9];
2
const result = [];
3
for (const id of usersToGet) {
4
const user = await {{ actions.getUser.trigger(id) }};
5
result.push(user);
6
}
7
return result;
Copied!
As the last step, add a table to display the obtained data.