Hi guys.
I need help to form a JSON output, I need to format it in a table for the body of the email that will be sent. Can anyone help me with any tips?
Thank you for your attention.
this is my test flow:
How is the body of the email:
Hi guys.
I need help to form a JSON output, I need to format it in a table for the body of the email that will be sent. Can anyone help me with any tips?
Thank you for your attention.
this is my test flow:
How is the body of the email:
You can use a template node and use mustache syntax to generate the html
or javascript in a Function node to loop through the data array with the same result.
Here is small example flow with JS
[{"id":"0d20057e4d5ebf5d","type":"inject","z":"54efb553244c241f","name":"data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"sales_month\":\"1992-01-01T00:00:00.000Z\",\"naics_code\":\"441\",\"kind_of_business\":\"Motor vehicle and parts dealers\",\"reason_for_null\":\"\",\"sales\":29811},{\"sales_month\":\"1992-01-01T00:00:00.000Z\",\"naics_code\":\"4411\",\"kind_of_business\":\"Automobile dealers\",\"reason_for_null\":\"\",\"sales\":25800}]","payloadType":"json","x":250,"y":3820,"wires":[["209cb742129d44fb"]]},{"id":"209cb742129d44fb","type":"function","z":"54efb553244c241f","name":"table","func":"// \"sales_month\": \"1992-01-01T00:00:00.000Z\",\n// \"naics_code\": \"4411\",\n// \"kind_of_business\": \"Automobile dealers\",\n// \"reason_for_null\": \"\",\n// \"sales\": 25800\n\nlet tableHtml = `<table>\n <tr>\n <td>Sales Month</td>\n <td>Naics Code</td>\n <td>Kind of business</td>\n <td>Reason for null</td>\n <td>Sales</td>\n </tr>\n ` \nmsg.payload.forEach(el => {\n tableHtml += `<tr>\n <td>${el.sales_month}</td>\n <td>${el.naics_code}</td>\n <td>${el.kind_of_business}</td>\n <td>${el.reason_for_null}</td>\n <td>${el.sales}</td>\n </tr>`\n })\n\ntableHtml += `</table>`\n\nmsg.payload = tableHtml\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":3820,"wires":[["608246100beee2a2"]]},{"id":"608246100beee2a2","type":"debug","z":"54efb553244c241f","name":"debug 23","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":3820,"wires":[]}]
You will need some styling and alignment to make it more presentable.
Thanks so much for the example, it was super helpful!
You could also use uibuilde's uib-element and uib-html to generate an html table from source data.