# Do not write columns if there is no data

**URL:** <https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035>\
**Category:** General\
**Created:** [13 July 2022 07:37 UTC](https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035 "2022-07-13T07:37:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discourse.nodered.org/u/Mauri)\
**Post date:** [13 July 2022 07:37 UTC](https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035/1 "2022-07-13T07:37:37Z")

</div>

Hello Community

I generate a pdf-file with node-red. Inside this dokument i work with columns. Now my question: Can I write a script that won't write the column if there is no data?

```auto
	{text: 'Heizung', style: 'header', decoration: 'underline'},
		{
		    columns: [
		        {
		            type: 'none',
		            ul: [
		                {text: 'Zählerart', fontSize: 8},
		                {text: 'Wärmezähler'}
                    ]
		        },
		        {
		            type: 'none',
		            ul: [
		                {text: 'Zähler-ID', fontSize: 8},
		                {text: global.get("0x_0x_we_id")}
                    ]
		        },
		        {
		            type: 'none',
		            ul: [
		                {text: 'Zählerstand alt', fontSize: 8},
		                {text: global.get("0x_0x_we_alt")+' '+'kWh'}
                    ]
		        },
                {
                    type: 'none',
                    ul: [
                        {text: 'Zählerstand neu', fontSize: 8},
                        {text: global.get("0x_0x_we_neu")+' '+'kWh'}
                    ]
                },
                {
                    type: 'none',
                    ul: [
                        {text: 'Differenz', fontSize: 8},
                        {text: global.get("0x_0x_we_diff")+' '+'kWh'}
                    ]
                }
		        
            ]
		},

```

If there is no data in "0x\_0x\_we\_id" or it's " = 0" then the column should nod be written...

Thanks for your answers!  
CU Mauri

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2022 09:04 UTC](https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035/2 "2022-07-13T09:04:04Z")

</div>

I have had to make assumptions of your object as it is a section and not a complete object.

I would create a column list and use that to create the columns, I would set up your initial object and leave columns empty, I would the push the items from column list if they pass conditionals.  
e.g.

```auto
[{"id":"93318f82.625168","type":"inject","z":"bf9e1e33.030598","name":"1","props":[{"p":"global_context","v":"1","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":2080,"wires":[["5159e2e6.9ec724"]]},{"id":"5159e2e6.9ec724","type":"function","z":"bf9e1e33.030598","name":"","func":"column_list = [\n {\"type\": \"none\", \"text\": [\"Zählerart\",\"Wärmezähler\"],\"fontSize\":8},\n {\"type\": \"none\", \"text\": [\"Zähler-ID\",msg.global_context],\"fontSize\":8} // any context or var could be used here\n];\n\nmsg.payload = [{text: 'Heizung', style: 'header', decoration: 'underline'},\n\t{\n\t\tcolumns: []\n\t}\n];\ncolumn_list.forEach(obj => {\n if(obj.text[1]){\n msg.payload[1].columns.push({\n type: obj.type,\n\t\t ul: [\n\t\t {text: obj.text[0], fontSize: obj.fontSize},\n\t\t {text: obj.text[1]}\n ]\n\t })\n }\n});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":2080,"wires":[["7dae4206.4a76f4"]]},{"id":"fa8a79c0.7b1ea8","type":"inject","z":"bf9e1e33.030598","name":"0","props":[{"p":"global_context","v":"0","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":2120,"wires":[["5159e2e6.9ec724"]]},{"id":"7dae4206.4a76f4","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":2080,"wires":[]}]

```

```auto
column_list = [
    {"type": "none", "text": ["Zählerart","Wärmezähler"],"fontSize":8},
    {"type": "none", "text": ["Zähler-ID",msg.global_context],"fontSize":8} // any context or var could be used here
];

msg.payload = [{text: 'Heizung', style: 'header', decoration: 'underline'},
	{
		columns: []
	}
];
column_list.forEach(obj => {
    if(obj.text[1]){
        msg.payload[1].columns.push({
            type: obj.type,
		    ul: [
		        {text: obj.text[0], fontSize: obj.fontSize},
		        {text: obj.text[1]}
            ]
	    })
    }
});
return msg;

```

---

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discourse.nodered.org/u/Mauri)\
**Post date:** [13 July 2022 09:22 UTC](https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035/3 "2022-07-13T09:22:46Z")

</div>

The full code is to big to show all, but you can show it in this txt file

```auto
[
    {
        "id": "85cf28dd7d884341",
        "type": "function",
        "z": "0df7cbc7b280fbe5",
        "name": "Abrechnung erstellen",
        "func": "var dd = {\n\tcontent: [\n\t\t{text: global.get(\"00_00_name_owner\")},\n\t\t{text: global.get(\"00_00_adr_owner\")},\n\t\t{text: global.get(\"00_00_plz_owner\") + \" \" + global.get(\"00_00_ort_owner\")},\n\t\t{\n\t\t\tcolumns: [\n\t\t\t\t{\n\t\t\t\t\tul: [\n\t\t\t\t\t\t\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tul: [\n\t\t\t\t\t\t\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t type: 'none',\n\t\t\t\t\tol:[\n\t\t\t\t\t\tglobal.get(\"00_00_allg_datum\"),\n\t\t\t\t\t\t{text: ' '},\n\t\t\t\t\t\tglobal.get(\"0x_0x_whg_bez\"),\n\t\t\t\t\t\t{text: global.get(\"0x_0x_name_mieter\"), style: 'header'},\n\t\t\t\t\t\tglobal.get(\"0x_00_adr_objekt\"),\n\t\t\t\t\t\tglobal.get(\"0x_00_plz_objekt\") + \" \" + global.get(\"0x_00_ort_objekt\")\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{text: ' '},\n\t\t{text: 'Zeitraum von' + \" \" + global.get(\"00_00_zr_start\")+ \" \" + 'bis' + \" \" + global.get(\"00_00_zr_ende\"), style: 'header', decoration: 'underline', fontSize: 15},\n\t\t{text: \" \"},\n\t\t{text: \" \"},\n\t\t{text: 'Ihre Abrechnung', style: 'header', decoration: 'underline'},\n\t\t{\n\t\t columns: [\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: 'Ihre Gesamtkosten', decoration: 'underline'},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text:'CHF'+' '+ global.get(\"0x_0x_kosten_mieter\"), decoration: 'underline'}\n]\n\t\t }\n ]\n\t\t},\n\t\t{text: \" \"},\n\t\t{text: \" \"},\n\t\t{text: \" \"},\n\t\t\n\t\t{text: 'Ihre Ablese- und Verbrauchswerte', style: 'header', decoration: 'underline'},\n\t\t{\n\t\t columns: [\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: 'Zählerart', fontSize: 10, style: 'header'},\n\t\t {text: 'Wärmezähler', fontSize: 8},\n\t\t {text: 'Warmwasserzähler', fontSize: 8},\n\t\t {text: 'Kaltwasserzähler', fontSize: 8},\n\t\t {text: 'Strom', fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: 'Zähler-ID', fontSize: 10, style:'header'},\n\t\t {text: global.get(\"0x_0x_we_id\"), fontSize: 8},\n\t\t {text: global.get(\"0x_0x_ww_id\"), fontSize: 8},\n\t\t {text: global.get(\"0x_0x_kw_id\"), fontSize: 8},\n\t\t {text: global.get(\"0x_0x_el_id\"), fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: 'Zählerstand alt', fontSize: 10, style:'header'},\n\t\t {text: global.get(\"0x_0x_we_alt\")+' '+ 'kWh', fontSize: 8},\n\t\t {text: global.get(\"0x_0x_ww_alt\")+' '+'m³', fontSize: 8},\n\t\t {text: global.get(\"0x_0x_kw_alt\")+' '+'m³', fontSize: 8},\n\t\t {text: global.get(\"0x_0x_el_alt\")+' '+ 'kWh', fontSize: 8},\n]\n\t\t },\n {\n type: 'none',\n ul: [\n {text: 'Zählerstand neu', fontSize: 10, style:'header'},\n {text: global.get(\"0x_0x_we_neu\")+' '+ 'kWh', fontSize: 8},\n {text: global.get(\"0x_0x_ww_neu\")+' '+'m³', fontSize: 8},\n {text: global.get(\"0x_0x_kw_neu\")+' '+'m³', fontSize: 8},\n {text: global.get(\"0x_0x_el_neu\")+' '+ 'kWh', fontSize: 8},\n]\n },\n {\n type: 'none',\n ul: [\n {text: 'Differenz', fontSize: 10, style:'header'},\n {text: global.get(\"0x_0x_we_diff\")+' '+ 'kWh', fontSize: 8},\n {text: global.get(\"0x_0x_ww_diff\")+' '+'m³', fontSize: 8},\n {text: global.get(\"0x_0x_kw_diff\")+' '+'m³', fontSize: 8},\n {text: global.get(\"0x_0x_el_diff\")+' '+ 'kWh', fontSize: 8},\n]\n }\n\t\t \n ]\n\t\t},\n\t\t\n\t\t{text: \" \"},\n\t\t{text: 'Aufstellung Wärmekosten', style: 'header', decoration: 'underline'},\n\t\t{\n\t\t columns: [\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', fontSize: 10, style: 'header'},\n\t\t {text: ' ', fontSize: 8},\n\t\t {text: ' ', fontSize: 8},\n\t\t {text: 'Ermittlung der Heizkosten', fontSize: 8},\n\t\t {text: 'Kosten Heizung', fontSize: 8},\n\t\t {text: 'Anteil WW-Erwärmung -', fontSize: 8},\n\t\t {text: 'Anteil Heizkosten =', fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', fontSize: 10, style: 'header'},\n\t\t {text: 'Kosten Heizanlage :', fontSize: 10, style: 'header'},\n\t\t {text:'CHF'+' '+ global.get(\"0x_00_chf_wp\"), fontSize: 8, decoration: 'underline'},\n\t\t {text: ' ', fontSize: 8},\n\t\t {text: ' ', fontSize: 8},\n\t\t {text:'CHF'+' '+ global.get(\"0x_00_chf_wp\"), fontSize: 8},\n\t\t {text:'CHF'+' '+ global.get(\"0x_00_chf_ww\"), fontSize: 8},\n\t\t {text:'CHF'+' '+ global.get(\"0x_00_chf_we\"), fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', fontSize: 10, style: 'header'},\n\t\t {text: 'Gesamtwärme x', fontSize: 10, style: 'header'},\n\t\t {text: global.get(\"0x_00_el_wp\")+' '+'kWh', fontSize: 8, decoration: 'underline'},\n\t\t {text: ' ', fontSize: 8},\n\t\t {text: ' ', fontSize: 8},\n]\n\t\t },\n {\n type: 'none',\n ul: [\n {text: 'Wärmemenge für Warmwasser =', fontSize: 10, style: 'header'},\n {text: global.get(\"0x_00_we_ww\")+' '+'kWh', fontSize: 8, decoration: 'underline'},\n {text: ' ', fontSize: 8},\n {text: ' ', fontSize: 8},\n]\n },\n {\n type: 'none',\n ul: [\n {text: 'Anteil an WW von Gesamtheizkosten', fontSize: 10, style: 'header'},\n {text: 'CHF'+' '+ global.get(\"0x_00_chf_ww\"), fontSize: 8, decoration: 'underline'},\n {text: ' ', fontSize: 8},\n {text: ' ', fontSize: 8}\n]\n }\n\t\t \n ]\n\t\t},\n\t\t{text: \" \"},\n\t\t{text: 'Aufteilung der Heizkosten', style: 'header', decoration: 'underline'},\n\t\t{\n\t\t columns: [\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', style: 'header',fontSize: 10},\n\t\t {text: 'Kostenart', style: 'header', fontSize: 10},\n\t\t {text: 'Heizkosten', fontSize: 8},\n\t\t {text: 'davon', fontSize: 8},\n\t\t {text: global.get(\"0x_00_gkhz_pz\")+'%' + ' ' + 'GK Heizung', fontSize: 8},\n\t\t {text: global.get(\"0x_00_vkhz_pz\")+'%' + ' ' + 'VK Heizung', fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', style: 'header',fontSize: 10},\n\t\t {text: 'Gesamtbetrag :', style: 'header', fontSize: 10},\n\t\t {text: 'CHF'+' '+ global.get(\"0x_00_chf_we\"), fontSize: 8},\n\t\t {text: \" \", fontSize: 8},\n\t\t {text: 'CHF'+' '+ global.get(\"0x_00_gk_hz\"), fontSize: 8},\n\t\t {text: 'CHF'+' '+ global.get(\"0x_00_vk_hz\"), fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: 'Gesamteinheit Gebäude =', style: 'header', fontSize: 10},\n\t\t {text: \" \", fontSize: 8 },\n\t\t {text: \" \", fontSize: 8},\n\t\t {text: global.get(\"0x_00_m2_tot\")+\" \"+'m²', fontSize: 8},\n\t\t {text: global.get(\"0x_00_we_hz\")+' ' + 'kWh', fontSize: 8},\n]\n\t\t },\n {\n type: 'none',\n ul: [\n {text: 'Betrag pro Einheit x', style: 'header', fontSize: 10},\n {text: \" \", fontSize: 8},\n {text: \" \", fontSize: 8},\n {text: global.get(\"0x_00_einh_gkhz\"), fontSize: 8},\n {text: global.get(\"0x_00_einh_vkhz\"), fontSize: 8},\n]\n },\n {\n type: 'none',\n ul: [\n {text: ' ', style: 'header',fontSize: 10},\n {text: 'Ihre Einheiten =', style: 'header', fontSize: 10},\n {text: ' ', fontSize: 8},\n {text: ' ', fontSize: 8},\n {text: global.get(\"0x_0x_m2_mieter\")+\" \"+'m²', fontSize: 8},\n {text: global.get(\"0x_0x_we_diff\")+' ' + 'kWh', fontSize: 8},\n {text: \"Total:\", fontSize: 8, style: 'header'},\n]\n },\n {\n type: 'none',\n ul: [\n {text: ' ', style: 'header',fontSize: 10},\n {text: 'Ihr Kostenanteil', style: 'header', fontSize:10},\n {text:' ', fontSize: 8},\n {text:' ', fontSize: 8},\n {text: 'CHF'+' '+ global.get(\"0x_0x_gkhz_mieter\"), fontSize: 8}, \n {text: 'CHF'+' '+ global.get(\"0x_0x_vkhz_mieter\"), fontSize: 8}, \n {text: 'CHF'+' '+ global.get(\"0x_0x_we_kosten\"), style: 'header', fontSize: 8},\n]\n },\n \n ]\n\t\t},\n\t\t\t\t{text: \" \"},\n\t\t{text: 'Aufteilung der Warmwasserkosten', style: 'header', decoration: 'underline'},\n\t\t{\n\t\t columns: [\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', style: 'header',fontSize: 10},\n\t\t {text: 'Kostenart', style: 'header', fontSize: 10},\n\t\t {text: 'WW-Kosten', fontSize: 8},\n\t\t {text: 'davon', fontSize: 8},\n\t\t {text: global.get(\"0x_00_gkww_pz\")+'%' + ' ' + 'GK WW', fontSize: 8},\n\t\t {text: global.get(\"0x_00_vkww_pz\")+'%' + ' ' + 'VK WW', fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', style: 'header',fontSize: 10},\n\t\t {text: 'Gesamtbetrag :', style: 'header', fontSize: 10},\n\t\t {text: 'CHF'+' '+ global.get(\"0x_00_chf_ww\"), fontSize: 8},\n\t\t {text: \" \", fontSize: 8},\n\t\t {text: 'CHF'+' '+ global.get(\"0x_00_gk_ww\"), fontSize: 8},\n\t\t {text: 'CHF'+' '+ global.get(\"0x_00_vk_ww\"), fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: 'Gesamteinheit Gebäude =', style: 'header', fontSize: 10},\n\t\t {text: \" \", fontSize: 8 },\n\t\t {text: \" \", fontSize: 8},\n\t\t {text: global.get(\"0x_00_m2_tot\")+\" \"+'m²', fontSize: 8},\n\t\t {text: global.get(\"0x_00_we_ww\")+' ' + 'kWh', fontSize: 8},\n]\n\t\t },\n {\n type: 'none',\n ul: [\n {text: 'Betrag pro Einheit x', style: 'header', fontSize: 10},\n {text: \" \", fontSize: 8},\n {text: \" \", fontSize: 8},\n {text: global.get(\"0x_00_einh_gkww\"), fontSize: 8},\n {text: global.get(\"0x_00_einh_vkww\"), fontSize: 8},\n]\n },\n {\n type: 'none',\n ul: [\n {text: ' ', style: 'header',fontSize: 10},\n {text: 'Ihre Einheiten =', style: 'header', fontSize: 10},\n {text: ' ', fontSize: 8},\n {text: ' ', fontSize: 8},\n {text: global.get(\"0x_0x_m2_mieter\")+\" \"+'m²', fontSize: 8},\n {text: global.get(\"0x_0x_ww_diff\")+' ' + 'kWh', fontSize: 8},\n {text: \"Total:\", fontSize: 8, style: 'header'},\n]\n },\n {\n type: 'none',\n ul: [\n {text: ' ', style: 'header',fontSize: 10},\n {text: 'Ihr Kostenanteil', style: 'header', fontSize:10},\n {text:' ', fontSize: 8},\n {text:' ', fontSize: 8},\n {text: 'CHF'+' '+ global.get(\"0x_0x_gkww_mieter\"), fontSize: 8}, \n {text: 'CHF'+' '+ global.get(\"0x_0x_vkww_mieter\"), fontSize: 8}, \n {text: 'CHF'+' '+ global.get(\"0x_0x_ww_kosten\"), style: 'header', fontSize: 8},\n]\n },\n \n ]\n\t\t},\n\t\n\t\t{text: \" \"},\n\t\t{text: 'Aufstellung Wasserkosten', style: 'header', decoration: 'underline'},\n\t\t{\n\t\t columns: [\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', style: 'header',fontSize: 10},\n\t\t {text: 'Kostenart', style: 'header', fontSize: 10},\n\t\t {text: 'Frischwasser', fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', style: 'header',fontSize: 10},\n\t\t {text: 'Gesamtbetrag :', style: 'header', fontSize: 10},\n\t\t {text: 'CHF'+' '+ global.get(\"0x_00_wsk_ges\"), fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: 'Gesamteinheit Gebäude =', style: 'header', fontSize: 10},\n\t\t {text: global.get(\"0x_00_ws_ges\")+\" \"+'m³', fontSize: 8},\n]\n\t\t },\n {\n type: 'none',\n ul: [\n {text: 'Betrag pro Einheit x', style: 'header', fontSize: 10},\n {text: global.get(\"0x_00_einh_ws\"), fontSize: 8},\n]\n },\n {\n type: 'none',\n ul: [\n {text: ' ', style: 'header', fontSize: 10},\n {text: 'Ihre Einheiten =', style: 'header', fontSize: 10},\n {text: global.get(\"0x_0x_ws_ges\")+\" \"+'m³', fontSize: 8},\n]\n },\n {\n type: 'none',\n ul: [\n {text: ' ', style: 'header', fontSize: 10},\n {text: 'Ihr Kostenanteil', style: 'header', fontSize: 10},\n {text: 'CHF'+' '+ global.get(\"0x_0x_wk_mieter\"), style: 'header', fontSize: 8},\n]\n },\n\t\t \n ]\n\t\t},\n\t\t{text: \" \"},\n\t\t{text: 'Aufstellung Stromkosten', style: 'header', decoration: 'underline'},\n\t\t{\n\t\t columns: [\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', style: 'header',fontSize: 10},\n\t\t {text: 'Kostenart', style: 'header', fontSize: 10},\n\t\t {text: 'Strom', fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: ' ', style: 'header',fontSize: 10},\n\t\t {text: 'Gesamtbetrag :', style: 'header', fontSize: 10},\n\t\t {text: 'CHF'+' '+ global.get(\"0x_00_elk_bez\"), fontSize: 8},\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text: 'Gesamteinheit Gebäude =', style: 'header', fontSize: 10},\n\t\t {text: global.get(\"0x_00_el_bez\")+' ' + 'kWh', fontSize: 8},\n]\n\t\t },\n {\n type: 'none',\n ul: [\n {text: 'Betrag pro Einheit x', style: 'header', fontSize: 10},\n {text: global.get(\"0x_00_tarif_mt\"), fontSize: 8},\n]\n },\n {\n type: 'none',\n ul: [\n {text: ' ', style: 'header', fontSize: 10},\n {text: 'Ihre Einheiten =', style: 'header', fontSize: 10},\n {text: global.get(\"0x_0x_el_diff\")+' ' + 'kWh', fontSize: 8},\n]\n },\n {\n type: 'none',\n ul: [\n {text: ' ', style: 'header', fontSize: 10},\n {text: 'Ihr Kostenanteil', style: 'header', fontSize: 10},\n {text: 'CHF'+' '+ global.get(\"0x_0x_sk_mieter\"), style: 'header', fontSize: 8,},\n]\n },\n\t\t \n ]\n\t\t},\n\t],\n\tstyles: {\n\t header: {\n\t bold: true,\n\t fontSize: 12\n\t }\n\t},\n\tdeafultStyle: {\n\t fontSize: 12\n\t}\n}\n\n\n\n\nmsg.payload = dd;\n\nconst saveplace = global.get(\"0x_00_pdf_speicherort\")\nconst reportName = global.get(\"00_00_zr_start\") + \" \" + global.get(\"00_00_zr_ende\") +\" \"+ global.get(\"0x_0x_name_mieter\")\nmsg.filename =`${saveplace}${reportName}.pdf`\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 960,
        "y": 2400,
        "wires": [
            [
                "cf21d173d24640c3"
            ]
        ]
    }
]

```

Always if the global variable "....\_id" is == 0 then the full column should not be written... You know what i mean?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2022 13:22 UTC](https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035/4 "2022-07-13T13:22:37Z")

</div>

Do you mean the full columns array or the columns element/index.

you may need to supply an copy of the object as it would appear if all id's are present, and a copy of how it should appear if a id is equal to 0. As I am not 100% sure what you mean.

---

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discourse.nodered.org/u/Mauri)\
**Post date:** [18 July 2022 18:19 UTC](https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035/5 "2022-07-18T18:19:05Z")

</div>

I think I mean the full columns array....

Ok, if all ID's are present, the object look like this:

```auto
{"content":[{"text":"CFM Automation"},{"text":"Wiesenstrasse 26"},{"text":"5400 Baden"},{"columns":[{"ul":[]},{"ul":[]},{"type":"none","ol":["31.12.2021",{"text":" "},"EG mitte",{"text":"Maurus Andreas Streiff","style":"header"},"Farnsburgerstrasse 37","4466 Ormalingen"]}]},{"text":" "},{"text":"Zeitraum von 01.01.2021 bis 31.12.2021","style":"header","decoration":"underline","fontSize":15},{"text":" "},{"text":"Heizung","style":"header","decoration":"underline"},{"columns":[{"type":"none","ul":[{"text":"Zählerart","fontSize":8},{"text":"Wärmezähler"}]},{"type":"none","ul":[{"text":"Zähler-ID","fontSize":8},{"text":0}]},{"type":"none","ul":[{"text":"Zählerstand alt","fontSize":8},{"text":"10519.4 Wh"}]},{"type":"none","ul":[{"text":"Zählerstand neu","fontSize":8},{"text":"10550.4 Wh"}]},{"type":"none","ul":[{"text":"Differenz","fontSize":8},{"text":"31 Wh"}]}]},{"text":" "},{"text":"Strom","style":"header","decoration":"underline"},{"columns":[{"type":"none","ul":[{"text":"Zählerart","fontSize":8},{"text":"Elektrozähler"}]},{"type":"none","ul":[{"text":"Zähler-ID","fontSize":8},{"text":7890123456}]},{"type":"none","ul":[{"text":"Zählerstand alt","fontSize":8},{"text":"49324.2 Wh"}]},{"type":"none","ul":[{"text":"Zählerstand neu","fontSize":8},{"text":"49241.2 Wh"}]},{"type":"none","ul":[{"text":"Differenz","fontSize":8},{"text":"-18223 Wh"}]}]},{"text":" "},{"text":"Warmwasser","style":"header","decoration":"underline"},{"columns":[{"type":"none","ul":[{"text":"Zählerart","fontSize":8},{"text":"Durchflusszähler"}]},{"type":"none","ul":[{"text":"Zähler-ID","fontSize":8},{"text":791038230}]},{"type":"none","ul":[{"text":"Zählerstand alt","fontSize":8},{"text":"122.1 m³"}]},{"type":"none","ul":[{"text":"Zählerstand neu","fontSize":8},{"text":"152.22 m³"}]},{"type":"none","ul":[{"text":"Differenz","fontSize":8},{"text":"30.12 m³"}]}]},{"text":" "},{"text":"Kaltwasser","style":"header","decoration":"underline"},{"columns":[{"type":"none","ul":[{"text":"Zählerart","fontSize":8},{"text":"Durchflusszähler"}]},{"type":"none","ul":[{"text":"Zähler-ID","fontSize":8},{"text":619816740}]},{"type":"none","ul":[{"text":"Zählerstand alt","fontSize":8},{"text":"173.62 m³"}]},{"type":"none","ul":[{"text":"Zählerstand neu","fontSize":8},{"text":"211.34 m³"}]},{"type":"none","ul":[{"text":"Differenz","fontSize":8},{"text":"37.72 m³"}]}]}],"styles":{"header":{"bold":true,"fontSize":12}},"deafultStyle":{"fontSize":12}}

```

Per example the ID from the heat counter does not exist, the object should look like following code:

```auto
{"content":[{"text":"CFM Automation"},{"text":"Wiesenstrasse 26"},{"text":"5400 Baden"},{"columns":[{"ul":[]},{"ul":[]},{"type":"none","ol":["31.12.2021",{"text":" "},"EG mitte",{"text":"Maurus Andreas Streiff","style":"header"},"Farnsburgerstrasse 37","4466 Ormalingen"]}]},{"text":" "},{"text":"Zeitraum von 01.01.2021 bis 31.12.2021","style":"header","decoration":"underline","fontSize":15},{"text":" "},{"text":" "},{"text":"Strom","style":"header","decoration":"underline"},{"columns":[{"type":"none","ul":[{"text":"Zählerart","fontSize":8},{"text":"Elektrozähler"}]},{"type":"none","ul":[{"text":"Zähler-ID","fontSize":8},{"text":7890123456}]},{"type":"none","ul":[{"text":"Zählerstand alt","fontSize":8},{"text":"49324.2 Wh"}]},{"type":"none","ul":[{"text":"Zählerstand neu","fontSize":8},{"text":"49241.2 Wh"}]},{"type":"none","ul":[{"text":"Differenz","fontSize":8},{"text":"-18223 Wh"}]}]},{"text":" "},{"text":"Warmwasser","style":"header","decoration":"underline"},{"columns":[{"type":"none","ul":[{"text":"Zählerart","fontSize":8},{"text":"Durchflusszähler"}]},{"type":"none","ul":[{"text":"Zähler-ID","fontSize":8},{"text":791038230}]},{"type":"none","ul":[{"text":"Zählerstand alt","fontSize":8},{"text":"122.1 m³"}]},{"type":"none","ul":[{"text":"Zählerstand neu","fontSize":8},{"text":"152.22 m³"}]},{"type":"none","ul":[{"text":"Differenz","fontSize":8},{"text":"30.12 m³"}]}]},{"text":" "},{"text":"Kaltwasser","style":"header","decoration":"underline"},{"columns":[{"type":"none","ul":[{"text":"Zählerart","fontSize":8},{"text":"Durchflusszähler"}]},{"type":"none","ul":[{"text":"Zähler-ID","fontSize":8},{"text":619816740}]},{"type":"none","ul":[{"text":"Zählerstand alt","fontSize":8},{"text":"173.62 m³"}]},{"type":"none","ul":[{"text":"Zählerstand neu","fontSize":8},{"text":"211.34 m³"}]},{"type":"none","ul":[{"text":"Differenz","fontSize":8},{"text":"37.72 m³"}]}]}],"styles":{"header":{"bold":true,"fontSize":12}},"deafultStyle":{"fontSize":12}}

```

I hope you undterstand what I mean... If it help, i can generate a pdf with both ways. Maybe you can unterstand better then...

thx

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [18 July 2022 19:06 UTC](https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035/6 "2022-07-18T19:06:18Z")

</div>

I may not understand, but try something like this

create your dd.content array but leave it empty.  
Then you can push values if conditions are met.

The below examples shows how if msg.payload.id2 is missing that section is not pushed.

```auto
[{"id":"90a53194.dec4b","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.id1","v":"1","vt":"num"},{"p":"payload.id2","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":200,"y":960,"wires":[["58cd8c4a.324c1c"]]},{"id":"7b8feab7.0e19ac","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.id1","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":210,"y":1000,"wires":[["58cd8c4a.324c1c"]]},{"id":"58cd8c4a.324c1c","type":"function","z":"30af2d3e.d94ea2","name":"Abrechnung erstellen","func":"var dd = {\n\tcontent: [\n\t\t],\n\tstyles: {\n\t header: {\n\t bold: true,\n\t fontSize: 12\n\t }\n\t},\n\tdeafultStyle: {\n\t fontSize: 12\n\t}\n}\nif (msg.payload.id1){\n \tdd.content.push({text: global.get(\"00_00_name_owner\")});\n\t\tdd.content.push({text: global.get(\"00_00_adr_owner\")});\n\t\tdd.content.push({text: global.get(\"00_00_plz_owner\") + \" \" + global.get(\"00_00_ort_owner\")},\n \t\t{\n \t\t\tcolumns: [\n \t\t\t\t{\n\t \t\t\t\tul: [\n\t \t\t\t\t]\n\t\t \t\t},\n\t\t\t \t{\n\t\t\t\t \tul: [\n \t\t\t\t\t]\n \t\t\t\t},\n \t\t\t\t{\n \t\t\t\t type: 'none',\n \t\t\t\t\tol:[\n \t\t\t\t\t\tglobal.get(\"00_00_allg_datum\"),\n \t\t\t\t\t\t{text: ' '},\n \t\t\t\t\t\tglobal.get(\"0x_0x_whg_bez\"),\n \t\t\t\t\t\t{text: global.get(\"0x_0x_name_mieter\"), style: 'header'},\n \t\t\t\t\t\tglobal.get(\"0x_00_adr_objekt\"),\n \t\t\t\t\t\tglobal.get(\"0x_00_plz_objekt\") + \" \" + global.get(\"0x_00_ort_objekt\")\n \t\t\t\t\t]\n \t\t\t\t}\n \t\t\t]\n \t\t});\n}\nif(msg.payload.id2){\n \tdd.content.push({text: ' '});\n\t\tdd.content.push({text: 'Zeitraum von' + \" \" + global.get(\"00_00_zr_start\")+ \" \" + 'bis' + \" \" + global.get(\"00_00_zr_ende\"), style: 'header', decoration: 'underline', fontSize: 15});\n\t\tdd.content.push({text: \" \"});\n\t\tdd.content.push({text: \" \"});\n\t\tdd.content.push({text: 'Ihre Abrechnung', style: 'header', decoration: 'underline'},\n\t\t {\n\t\t columns: [\n\t\t {\n\t\t type: 'none',\n\t \t ul: [\n\t \t {text: 'Ihre Gesamtkosten', decoration: 'underline'},\n]\n\t \t },\n\t \t {\n\t \t type: 'none',\n\t \t ul: [\n]\n\t\t },\n\t\t {\n\t\t type: 'none',\n\t\t ul: [\n\t\t {text:'CHF'+' '+ global.get(\"0x_0x_kosten_mieter\"), decoration: 'underline'}\n]\n\t \t }\n ]\n\t \t}); \n}\n\t\n\nmsg.payload = dd;\n\nconst saveplace = global.get(\"0x_00_pdf_speicherort\")\nconst reportName = global.get(\"00_00_zr_start\") + \" \" + global.get(\"00_00_zr_ende\") +\" \"+ global.get(\"0x_0x_name_mieter\")\nmsg.filename =`${saveplace}${reportName}.pdf`\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":940,"wires":[["c75be667.e7b968"]]},{"id":"c75be667.e7b968","type":"debug","z":"30af2d3e.d94ea2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":840,"wires":[]}]

```

I used payload.id2 etc rather than context just for example, as i do not have your data or context store. Alter as needed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 September 2022 19:07 UTC](https://discourse.nodered.org/t/do-not-write-columns-if-there-is-no-data/65035/7 "2022-09-16T19:07:11Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
