JoseG
November 2, 2022, 12:35pm
1
Hi,
I created a flow where I have a node that queries a postgres database and I wanted to aggregate all the items into a table for emailing.
I tried to use the node Item lists to aggregate the query result, but then in the outlook node, I can’t get the email to be sent with the information.
Could someone help me please?
Thanks a lot!
Hi @JoseG , welcome to the community
I am sorry to hear you’re having trouble. Can you confirm which problem exactly you are seeing on the Outlook node?
JoseG
November 3, 2022, 12:46pm
3
Hi @MutedJam
Thank you very much for your answer!
Actually what I want is to send an email with the result of all the rows that the query returns, not an email for each row which is what was happening to me.
I think I’m already pretty close to what I want:
let email_html = `<html>
<div>
<table>
<tr>
<th>Ticket ID</th>
<th>Description</th>
<th>Priority</th>
<th>Created Date</th>
<th>Resolved Date</th>
<th>Status</th>
<th>Days</th>
</tr>`;
for (item of $input.all()) {
email_html += `<tr>
<td>${item.json.ticket_id}</td>
<td>${item.json.ticket_description}</td>
<td>${item.json.ticket_priority}</td>
<td>${item.json.created_date}</td>
<td>${item.json.resolved_date}</td>
<td>${item.json.ticket_status}</td>
<td>${item.json.ticket_days}</td>
</tr>
`;
}
email_html += `</table></div></html>`
return [{
json: {
email_html: email_html
}
}];
But now I have run into another difficulty that I am not being able to fetch a nested item:
I need to fetch the value of days: which is inside the ticket_days field.
Could you help me how I can do it, please?
Thank you very much!
That’s looking good indeed. Nested fields should be available with the dot notation. So if you have a JSON object like this:
{
"ticket_days": {
"days": 30
}
}
The days
value could be referenced with ticket_days.days
. So perhaps you can try ${item.json.ticket_days.days}
in your code?
JoseG
November 3, 2022, 2:27pm
5
Hi @MutedJam
Yes I had already tried this code ${item.json.ticket_days.days} and when running the node it gives this error:
Ah, that’ll probably be because not all of your items have a ticket_days
property. Perhaps you can try ${item.json?.ticket_days?.days}
instead? This is called optional chaining and should deal with this situation.
2 Likes
Amazing, thanks so much for confirming!
system
Closed
November 10, 2022, 3:45pm
9
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.