Use actions.name.trigger ()
Sometimes, you will need to handle the result of another action or execute some actions in bulk using JavaScript. In these cases, you can use await actions.action.trigger()
syntax, 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.
Basic setup
In the basic setup, you can use await actions.actionName.trigger()
anywhere in your app actions code, like this:
It is also possible to pass custom parameters to the action:
The parameters will be available as {{params}}
variable in any action step.
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:
Add a new action - Load Table. Select Order Details table as a resource. Make sure the action is titled as loadOrderDetails.
Configure selected record field as
Order Number ={{data}}.
Next up, add another action - Load Row. Select Orders table as a resource. Make sure the action is titled as loadOrder.
Configure selected record field as
Order Number ={{data}}
.Now, to combine the data from both the actions, add a new action - Code. Rename it to loadDetails and specify the code:
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:
Add a new action loadOrderDetails - Load Table. Select Order Details table as a resource.
Configure selected record field as
Order Number ={{data}}
Add a new Workflow: load Orders table as a first step. For testing purposes, we recommend setting the limit to 10 records.
Add a Code step with the below code as a second step:
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.
Add a new action getUser - HTTP request. Select the data source, set
GET
method, specify the URL as{{data}}
Add the next action getUsers - Code. Specify the below code:
As the last step, add a table to display the obtained data.
Last updated