Transform Node
Accessing Flow Variables
$.myApiNode
$.myApiNode.data
$.myAnotherNodeIdReal-world Example
/* Data structure of invoices:
[
{
id: 1,
your_name: "My Company",
your_street: "Street 123",
your_city: "Prague",
your_country: "CZ",
client_name: "Client Company",
client_street: "Street 456",
client_city: "London",
client_country: "UK",
subject_id: 1, // Unique ID of client
total: 24350,
...
}
]
*/
const invoices = $.apiInvoice.data;
// Let's create a map of Subject (customer) -> { info, total amount }
const subjects = new Map();
// Iterate through all invoices
for (let i = 0; i < invoices.length; i++) {
const invoice = invoices[i];
// If the subject (customer) does not exist in the map, create it
if (!subjects.has(invoice.subject_id)) {
subjects.set(invoice.subject_id, {
// Store info about the subject
subject_id: invoice.subject_id,
name: invoice.client_name,
street: invoice.client_street,
city: invoice.client_city,
client_country: invoice.client_country,
// Prepare the total amount counter
total: 0
});
}
// Add invoice amount to the subject
const subject = subjects.get(invoice.subject_id);
subject.total += parseFloat(invoice.total);
}
// Return subjects as an array so we can work with them in UI more easily (like displaying them in a table)
return Array.from(subjects.values());Last updated
Was this helpful?
