Send query results to email with workflow

Hi, need some help here
to send query results to email with workflow
I don't see the results in the email body
thanks

You need to loop over or or concatenate data.

Try stock_less_500.data[0].item_name or stock_less_500.data.item_name[0] or something. I’m on my cellphone so I can’t really check it.

When you know what the structure of the data is you can use reducing to make it a string. A string you can add to your e-mail like you are doing now.


// Example array
const stock_less_500 = {
  data: [
    { item_name: 'Item1', stock: 300 },
    { item_name: 'Item2', stock: 150 },
    { item_name: 'Item3', stock: 450 },
    // Add more items as needed
  ]
};

// Using lodash's reduce function to create a string
const resultString = _.reduce(stock_less_500.data, (result, item) => {
  return result + `${item.item_name}: ${item.stock}, `;
}, '');

// Remove the trailing comma and space if needed
const finalString = resultString.slice(0, -2);

console.log(finalString); // Output: "Item1: 300, Item2: 150, Item3: 450"

From chatgpt. Not sure if you can copy paste it. But should be close. I would add an js block between the query and the email to run this code. You need to remove the example array though: const stock_less_500

If you return final string at the end: return finalString;

You can use {{code1.data}} as the string in your email template.