I have a simple flow, where i convert the contents of a CSV file into an HTML table for sending it as email body.
for few rows in the table i need to colspan 6 columns so that they appear in a single cell based on the contents. i can make the starting of the content to anything i like, here in the example it SUM1, SUM2 etc..
I am not able to write a conditioal code to do that. a little help please.
I can write the same in a static code, but when using dynamic code (inspired by this post)
CSV to HTML dynamic code
sample code to work with
[{"id":"ddcffe189e25e957","type":"inject","z":"70c85b46b7f69ea5","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":230,"y":1680,"wires":[["0fdc97d6f3010d9e"]]},{"id":"8152b6f5488faf5e","type":"function","z":"70c85b46b7f69ea5","name":"CSV to HTML","func":"var html = '<!doctype html><html lang=\"en\"><table border=\"1\" Style= \"border: 1px solid pink; font-size:12px; border-collapse:collapse;\"><tr><td colspan = \"6\"><h3>Online Downtime Report (Hosur) for the date '+msg.ddate+'</h3></td></tr>';\n\n//var html = '<!doctype html><html lang=\"en\"><table border=\"1\" Style= \"font-size:12px; border-collapse:collapse;\"><tr><td colspan = \"5\"><h3>Online Downtime Report</h3></td></tr>';\nhtml += '<td width=\"100px\"></td><td width=\"110px\"></td><td width=\"110px\"></td><td width=\"90px\"></td><td width=\"260px\"></td><td width=\"260px\"></td>'+' </tr>';\n\nmsg.payload.forEach((part) => {\n html += '<tr>';\n Object.values(part).forEach((bits) => {\n html += '<td>'+bits+'</td>'\n })\n html+= '</tr>';\n})\nmsg.payload = html+'</table></html>';\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":1680,"wires":[["dc879725.5e20d","f1b09195b2116af4"]]},{"id":"f1b09195b2116af4","type":"debug","z":"70c85b46b7f69ea5","name":"Debug-1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":1680,"wires":[]},{"id":"0fdc97d6f3010d9e","type":"change","z":"70c85b46b7f69ea5","name":"Sample Data","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\"col1\":\"Machine\",\"col2\":\"Time-From\",\"col3\":\"Time-To\",\"col4\":\"Duration\",\"col5\":\"Reason-1\",\"col6\":\"Reason-2\"},{\"col1\":\"MACHINE-1\",\"col2\":\"19-Jan-25 14:04\",\"col3\":\"19-Jan-25 14:12\",\"col4\":8,\"col5\":\"-\",\"col6\":\"-\"},{\"col1\":\"Machine\",\"col2\":\"Time-From\",\"col3\":\"Time-To\",\"col4\":\"Duration\",\"col5\":\"Reason-1\",\"col6\":\"Reason-2\"},{\"col1\":\"MACHINE-2\",\"col2\":\"19-Jan-25 05:59\",\"col3\":\"19-Jan-25 06:12\",\"col4\":13,\"col5\":\"-\",\"col6\":\"-\"},{\"col1\":\"MACHINE-2\",\"col2\":\"19-Jan-25 06:13\",\"col3\":\"19-Jan-25 06:34\",\"col4\":21,\"col5\":\"-\",\"col6\":\"-\"},{\"col1\":\"Machine\",\"col2\":\"Time-From\",\"col3\":\"Time-To\",\"col4\":\"Duration\",\"col5\":\"Reason-1\",\"col6\":\"Reason-2\"},{\"col1\":\"MACHINE-3\",\"col2\":\"19-Jan-25 05:59\",\"col3\":\"19-Jan-25 06:12\",\"col4\":13,\"col5\":\"-\",\"col6\":\"-\"},{\"col1\":\"Machine\",\"col2\":\"Time-From\",\"col3\":\"Time-To\",\"col4\":\"Duration\",\"col5\":\"Reason-1\",\"col6\":\"Reason-2\"},{\"col1\":\"MACHINE-4\",\"col2\":\"19-Jan-25 05:59\",\"col3\":\"19-Jan-25 13:59\",\"col4\":480,\"col5\":\"-\",\"col6\":\"-\"},{\"col1\":\"MACHINE-4\",\"col2\":\"19-Jan-25 14:00\",\"col3\":\"19-Jan-25 14:09\",\"col4\":9,\"col5\":\"-\",\"col6\":\"-\"},{\"col1\":\"Machine\",\"col2\":\"Time-From\",\"col3\":\"Time-To\",\"col4\":\"Duration\",\"col5\":\"Reason-1\",\"col6\":\"Reason-2\"},{\"col1\":\"MACHINE-5\",\"col2\":\"19-Jan-25 06:04\",\"col3\":\"19-Jan-25 06:09\",\"col4\":5,\"col5\":\"-\",\"col6\":\"-\"},{\"col1\":\"MACHINE-5\",\"col2\":\"19-Jan-25 06:11\",\"col3\":\"19-Jan-25 06:49\",\"col4\":38,\"col5\":\"-\",\"col6\":\"-\"},{\"col1\":\"SUM1-MACHINE-1 has produced 7,580 strokes on 2025-01-19\"},{\"col1\":\"SUM2-MACHINE-2 was not running on 2025-01-19\"},{\"col1\":\"SUM3-MACHINE-3 was not running on 2025-01-19\"},{\"col1\":\"SUM4-MACHINE-4 has produced 7,114 strokes on 2025-01-19\"},{\"col1\":\"SUM5-MACHINE-5 has produced 7,767 strokes on 2025-01-19\"}]","tot":"json"},{"t":"set","p":"ddate","pt":"msg","to":"19th Jan 2025","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":1680,"wires":[["8152b6f5488faf5e"]]}]
need something like, if the contents of col1 contains SUM in the begining,
<td colspan = "6">
...,
else <td>
...