Overview
You can use macros to run JavaScript code within your flows.
Macros are created and managed on the Macros page.
function checkEmpty(item) {
return item.getPropertyNumberValue('d4ae676b-49c3-4a06-8390-ff6b4d785ffc') !== 0;
}
function sumTotal(total, nextItem) {
return total + parseInt(
nextItem.getPropertyStringValue('842d8c71-9bb6-415d-883e-071ce549713a')
.substring(1)
) * nextItem.getPropertyNumberValue('d4ae676b-49c3-4a06-8390-ff6b4d785ffc');
}
const itemList = state.getArray('{![FL - Mock shopping app - Shopping Item List]}');
const basket = itemList. filter(checkEmpty);
state. setArray('{![FL - Mock shopping app - Shopping Item Basket]}', basket);
const total = basket.reduce(sumTotal, 0);
state.setNumberValue('{![FL - Mock shopping app - Basket Total]}', total);
-
The Macros page displays all the macros currently set up within the tenant. See Macros page
-
Create macros to execute JavaScript from within your flows only when steps do not provide sufficent funtionality to achieve your outcomes. For example, you could use a macro to perform complex calculations on numeric values within a flow. See Creating a macro.
-
You can insert a macro into your flows using the Operator step.
-
Macros are shared steps that can be imported into and used in multiple flows in a tenant. See Importing a macro into a flow.
-
Macros are not executed in the browser; they are executed on the server, inside the flow runtime engine, as flows support clients that may not be a browser with support for JavaScript (such as server-to-server communication, SMS interactions, phone calls and so on).
This means that flows support only a subset of JavaScript (ES5), excluding I/O and network functions like console.log, fs or fetch, or functions that interact with the DOM such as alert and getElementById. As such, or custom components should be used for interacting with libraries or asynchronous call outside of the Boomi Flow environment. See Supported macro JavaScript methods.