# Add value into a row of a CSV and append to Next Line

**URL:** <https://discourse.nodered.org/t/add-value-into-a-row-of-a-csv-and-append-to-next-line/80230>\
**Category:** General\
**Created:** [1 August 2023 17:16 UTC](https://discourse.nodered.org/t/add-value-into-a-row-of-a-csv-and-append-to-next-line/80230 "2023-08-01T17:16:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlabella](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mlabella](https://discourse.nodered.org/u/mlabella)\
**Post date:** [1 August 2023 17:16 UTC](https://discourse.nodered.org/t/add-value-into-a-row-of-a-csv-and-append-to-next-line/80230/1 "2023-08-01T17:16:48Z")

</div>

I am given a CSV file where the first column should have ID numbers that will be filled in when scanned, but for now I am just using a timestamp to test. The current flow I have made makes every row have the same ID number, but I just want to append to the next empty value to add another ID.  
I am given the CSV:

```auto
ID,PART#,BIN_QTY
,HHCS 1/4-20X1/2,300
,HHCS 1/4-20X3/4,300
,HHCS 1/4-20X1,300
,HHCS 1/4-20X1-1/4,250
,HHCS 1/4-20X1-1/2,250
,HHCS 1/4-20 X 1-3/4,250
,HHCS 1/4-20X2,250

```

I want to add to the first line an ID, and then append to the next line for when I inject a new ID to the next item.

```auto
ID,PART#,BIN_QTY
ef0087654,HHCS 1/4-20X1/2,300
,HHCS 1/4-20X3/4,300
,HHCS 1/4-20X1,300
,HHCS 1/4-20X1-1/4,250
,HHCS 1/4-20X1-1/2,250
,HHCS 1/4-20 X 1-3/4,250
,HHCS 1/4-20X2,250

```

Currently my flow just makes every single item the same ID with an output of

```auto
ID,PART#,BIN_QTY
ef0087654,HHCS 1/4-20X1/2,300
ef0087654,HHCS 1/4-20X3/4,300
ef0087654,HHCS 1/4-20X1,300
ef0087654,HHCS 1/4-20X1-1/4,250
ef0087654,HHCS 1/4-20X1-1/2,250
ef0087654,HHCS 1/4-20 X 1-3/4,250
ef0087654,HHCS 1/4-20X2,250

```

Here is my flow:

```auto
[
    {
        "id": "c57f2b0221605a05",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "6a6eec79effcd4d0",
        "type": "switch",
        "z": "c57f2b0221605a05",
        "name": "Check if RFID in CSV",
        "property": "payload.ID",
        "propertyType": "msg",
        "rules": [
            {
                "t": "null"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 640,
        "y": 140,
        "wires": [
            [
                "1eafbadef8d616a6"
            ],
            [
                "e742531873290a04"
            ]
        ]
    },
    {
        "id": "1eafbadef8d616a6",
        "type": "change",
        "z": "c57f2b0221605a05",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload.ID",
                "pt": "msg",
                "to": "rfidhex",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 890,
        "y": 120,
        "wires": [
            [
                "e742531873290a04"
            ]
        ]
    },
    {
        "id": "b55dce2557437759",
        "type": "inject",
        "z": "c57f2b0221605a05",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "rfidhex",
                "vt": "flow"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 140,
        "wires": [
            [
                "cb0fe7f35da038ad"
            ]
        ]
    },
    {
        "id": "e742531873290a04",
        "type": "join",
        "z": "c57f2b0221605a05",
        "name": "",
        "mode": "auto",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": "false",
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "x": 1110,
        "y": 140,
        "wires": [
            [
                "2f77e0fa882b503f"
            ]
        ]
    },
    {
        "id": "cb0fe7f35da038ad",
        "type": "template",
        "z": "c57f2b0221605a05",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "ID,PART#,BIN_QTY\n,HHCS 1/4-20X1/2,300\n,HHCS 1/4-20X3/4,300\n,HHCS 1/4-20X1,300\n,HHCS 1/4-20X1-1/4,250\n,HHCS 1/4-20X1-1/2,250\n,HHCS 1/4-20 X 1-3/4,250\n,HHCS 1/4-20X2,250\n,HHCS 1/4-20X2-1/4,200\n,HHCS 1/4-20X2-1/2,200\n,HHCS 1/4-20X2-3/4,150\n,HHCS 1/4-20X3,150\n,HHCS 1/4-20X3-1/2,100\n,HHCS 1/4-20X4,100\n,HEXNUT 1/4-20,500\n,FW 1/4,500\n,LW 1/4,500\n",
        "output": "str",
        "x": 300,
        "y": 140,
        "wires": [
            [
                "8db3881ef68fadf3"
            ]
        ]
    },
    {
        "id": "c38f36f021396e7f",
        "type": "template",
        "z": "c57f2b0221605a05",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "This is the payload: {{payload}} !",
        "output": "str",
        "x": 1380,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "673b13b3dc1ead54",
        "type": "inject",
        "z": "c57f2b0221605a05",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "ef0087654",
        "payloadType": "str",
        "x": 150,
        "y": 60,
        "wires": [
            [
                "ead1e44319b2ef3f"
            ]
        ]
    },
    {
        "id": "ead1e44319b2ef3f",
        "type": "change",
        "z": "c57f2b0221605a05",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "rfidhex",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 340,
        "y": 60,
        "wires": [
            []
        ]
    },
    {
        "id": "6a0652a1d9127c4f",
        "type": "debug",
        "z": "c57f2b0221605a05",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1430,
        "y": 220,
        "wires": []
    },
    {
        "id": "8db3881ef68fadf3",
        "type": "csv",
        "z": "c57f2b0221605a05",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "none",
        "multi": "one",
        "ret": "\\n",
        "temp": "ID,PART#,BIN_QTY",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": true,
        "x": 450,
        "y": 140,
        "wires": [
            [
                "6a6eec79effcd4d0"
            ]
        ]
    },
    {
        "id": "2f77e0fa882b503f",
        "type": "csv",
        "z": "c57f2b0221605a05",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "all",
        "multi": "one",
        "ret": "\\n",
        "temp": "ID,PART#,BIN_QTY",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 1230,
        "y": 140,
        "wires": [
            [
                "c38f36f021396e7f",
                "6a0652a1d9127c4f"
            ]
        ]
    }
]

```

---

<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:** [1 August 2023 18:02 UTC](https://discourse.nodered.org/t/add-value-into-a-row-of-a-csv-and-append-to-next-line/80230/2 "2023-08-01T18:02:37Z")

</div>

Every line the ID is null. Might be best to output the whole array of objects and target the object in index 0.  
e.g.

```auto
[{"id":"b55dce2557437759","type":"inject","z":"c57f2b0221605a05","name":"","props":[{"p":"index","v":"0","vt":"num"},{"p":"topic","v":"rfidhex","vt":"flow"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":120,"wires":[["cb0fe7f35da038ad"]]},{"id":"cb0fe7f35da038ad","type":"template","z":"c57f2b0221605a05","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"ID,PART#,BIN_QTY\n,HHCS 1/4-20X1/2,300\n,HHCS 1/4-20X3/4,300\n,HHCS 1/4-20X1,300\n,HHCS 1/4-20X1-1/4,250\n,HHCS 1/4-20X1-1/2,250\n,HHCS 1/4-20 X 1-3/4,250\n,HHCS 1/4-20X2,250\n,HHCS 1/4-20X2-1/4,200\n,HHCS 1/4-20X2-1/2,200\n,HHCS 1/4-20X2-3/4,150\n,HHCS 1/4-20X3,150\n,HHCS 1/4-20X3-1/2,100\n,HHCS 1/4-20X4,100\n,HEXNUT 1/4-20,500\n,FW 1/4,500\n,LW 1/4,500\n","output":"str","x":400,"y":120,"wires":[["8db3881ef68fadf3"]]},{"id":"8db3881ef68fadf3","type":"csv","z":"c57f2b0221605a05","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"mult","ret":"\\n","temp":"ID,PART#,BIN_QTY","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":true,"x":550,"y":120,"wires":[["eb8e226688c57eb0"]]},{"id":"eb8e226688c57eb0","type":"switch","z":"c57f2b0221605a05","name":"","property":"payload[msg.index].ID","propertyType":"msg","rules":[{"t":"null"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":120,"wires":[["1eafbadef8d616a6"],["2f77e0fa882b503f"]]},{"id":"1eafbadef8d616a6","type":"change","z":"c57f2b0221605a05","name":"","rules":[{"t":"set","p":"payload[msg.index].ID","pt":"msg","to":"rfidhex","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":100,"wires":[["2f77e0fa882b503f"]]},{"id":"2f77e0fa882b503f","type":"csv","z":"c57f2b0221605a05","name":"","sep":",","hdrin":true,"hdrout":"all","multi":"one","ret":"\\n","temp":"ID,PART#,BIN_QTY","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":1130,"y":120,"wires":[["6a0652a1d9127c4f"]]},{"id":"6a0652a1d9127c4f","type":"debug","z":"c57f2b0221605a05","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":260,"wires":[]}]

```

[edit] Forgot null check.

---

<div class="post-metadata">

**Author:** ![mlabella](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mlabella](https://discourse.nodered.org/u/mlabella)\
**Post date:** [1 August 2023 18:13 UTC](https://discourse.nodered.org/t/add-value-into-a-row-of-a-csv-and-append-to-next-line/80230/3 "2023-08-01T18:13:46Z")

</div>

I could not remember the index syntax, thank you for the refresher.

---

<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:** [15 August 2023 18:14 UTC](https://discourse.nodered.org/t/add-value-into-a-row-of-a-csv-and-append-to-next-line/80230/4 "2023-08-15T18:14:24Z")

</div>

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