# How to create Custom Node that has msg.payload value of all node properties combined ( in json format)

**URL:** <https://discourse.nodered.org/t/how-to-create-custom-node-that-has-msg-payload-value-of-all-node-properties-combined-in-json-format/15794>\
**Category:** Developing Nodes\
**Created:** [22 September 2019 20:32 UTC](https://discourse.nodered.org/t/how-to-create-custom-node-that-has-msg-payload-value-of-all-node-properties-combined-in-json-format/15794 "2019-09-22T20:32:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaya24](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jaya24](https://discourse.nodered.org/u/jaya24)\
**Post date:** [22 September 2019 20:32 UTC](https://discourse.nodered.org/t/how-to-create-custom-node-that-has-msg-payload-value-of-all-node-properties-combined-in-json-format/15794/1 "2019-09-22T20:32:33Z")

</div>

I am new to Node red.

I need to create Custom Node that has msg.payload value of all node properties combined ( in json format)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 September 2019 20:42 UTC](https://discourse.nodered.org/t/how-to-create-custom-node-that-has-msg-payload-value-of-all-node-properties-combined-in-json-format/15794/2 "2019-09-22T20:42:21Z")

</div>

Moved to #general as it’s not about a node that has been written

What have you tried? Where are you stuck? What node properties do you mean?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 September 2019 20:44 UTC](https://discourse.nodered.org/t/how-to-create-custom-node-that-has-msg-payload-value-of-all-node-properties-combined-in-json-format/15794/3 "2019-09-22T20:44:23Z")

</div>

> [@jaya24](#):
>
> Custom Node

Also clarify what you mean by Custom Node

---

<div class="post-metadata">

**Author:** ![jaya24](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jaya24](https://discourse.nodered.org/u/jaya24)\
**Post date:** [22 September 2019 20:58 UTC](https://discourse.nodered.org/t/how-to-create-custom-node-that-has-msg-payload-value-of-all-node-properties-combined-in-json-format/15794/4 "2019-09-22T20:58:39Z")

</div>

I am sorry. I am not very familiar with terminologies here.

I am creating a node  
Properties I am referring to : ![00%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2893086191e14794cc836b617c435be830486cf3.png)

I want the values input as msg.payload

This is my index.html file :

```auto
<script type="text/javascript">
    RED.nodes.registerType('AgFarm Farm',{
        category: 'Procurement',
        color: '#f5ed7a',
        defaults: {
            farmername: {value:""}
        },
        inputs:1,
        outputs:1,
        icon: "farm.png",
        label: function() {
            return this.farmername||"AgFarm Farm";
        }
    });
</script>

<script type="text/x-red" data-template-name="AgFarm Farm">
  <div class="form-row">
      <label for="node-input-agfarmid"><i class="icon-tag"></i> AgFarm ID</label>
      <input type="text" id="node-input-agfarmid" placeholder="AgFarm ID">
  </div>
    <div class="form-row">
        <label for="node-input-farmername"><i class="icon-tag"></i> Farmer's Name</label>
        <input type="text" id="node-input-farmername" placeholder="Farmer's Name">
    </div>
    <div class="form-row">
        <label for="node-input-village"><i class="icon-tag"></i> Village</label>
        <input type="text" id="node-input-village" placeholder="Village">
    </div>
    <div class="form-row">
        <label for="node-input-district"><i class="icon-tag"></i> District </label>
        <input type="text" id="node-input-district" placeholder="District">
    </div>
    <div class="form-row">
        <label for="node-input-state"><i class="icon-tag"></i> State</label>
        <input type="text" id="node-input-state" placeholder="State">
    </div>
    <div class="form-row">
        <label for="node-input-country"><i class="icon-tag"></i> Country</label>
        <input type="text" id="node-input-country" placeholder="Country">
    </div>
    <div class="form-row">
        <label for="node-input-rmlot"><i class="icon-tag"></i> RM Lot</label>
        <input type="text" id="node-input-rmlot" placeholder="RM Lot NUmber">
    </div>
</script>
 
<script type="text/x-red" data-help-name="swani node">
    <p>A node that increments every time a new message is received and sends Hello World in return.<br/>
    </p>
</script>

```

What should I place in outMsg variable

```auto
 module.exports = function(RED) {
    function swaninode(config) {
        RED.nodes.createNode(this,config);
        var context = this.context();
        var node = this;

        this.on('input', function(msg) {

        var outMsg = {payload: ""};

        node.send(outMsg);

        });
    }
    RED.nodes.registerType("AgFarm Farm",swaninode);
};

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 September 2019 22:13 UTC](https://discourse.nodered.org/t/how-to-create-custom-node-that-has-msg-payload-value-of-all-node-properties-combined-in-json-format/15794/5 "2019-09-22T22:13:38Z")

</div>

At the moment, you only have `farmername` listed in the `defaults` object of the html file. That means that is the only property the editor will save with your node. So step one is to add all the other properties you care about to that object.

Once you have done that, then the `config` object passed to your custom node's constructor function will contain them all as properties.

You can then copy them onto the payload of the message you receive.

In your current code, you are ignoring the msg object passed to your node and sending on a new object. That is a bad practice as it will lose any custom properties the user may have already placed on the message.

```auto

this.on('input', function(msg) {

        msg.payload = {
            farmername: config.farmername,
            anotherProperty: config.anotherProperty
        }

        node.send(msg);
})

```

---

<div class="post-metadata">

**Author:** ![jaya24](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jaya24](https://discourse.nodered.org/u/jaya24)\
**Post date:** [23 September 2019 03:40 UTC](https://discourse.nodered.org/t/how-to-create-custom-node-that-has-msg-payload-value-of-all-node-properties-combined-in-json-format/15794/6 "2019-09-23T03:40:15Z")

</div>

Thanks a lot . It worked. 🙂
