Unable to Use Node Properties in Node Runtime

Hello everyone,
I am trying to build my own node following docs. I want to add node properties like described in Node Properties.
I am able to add some extra properties beside Name property but when I try to send these properties along with the msg.payload, I get undefined in debug node. What am I doing wrong?

My runtime code:

module.exports = function(RED) {
    function LowerCaseNode(config) {
        RED.nodes.createNode(this,config);		
		this.other1 = config.other1;
		this.other2 = config.other2;
        var node = this;
        node.on('input', function(msg) {
            msg.payload = msg.payload.toLowerCase();
			node.send("Other1: " + node.other1);
			node.send("Other2: " + node.other2);
        });
    }
    RED.nodes.registerType("lower-case",LowerCaseNode);
}

My Node template:

<script type="text/javascript">
    RED.nodes.registerType('lower-case',{
        category: 'function',
        color: '#a6bbcf',
        defaults: {
            name: {value:""},
			other1: {value:""},
			other2: {value:""}
        },
        inputs:1,
        outputs:1,
        icon: "file.png",
        label: function() {
            return this.name||"lower-case";
        }
    });
</script>

<script type="text/html" data-template-name="lower-case">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
	</div>
	<div class="form-row">
		<label for="node-input-other1"><i class="icon-tag"></i> Other1</label>
		<input type="text" id="node-input-other1">
	</div>
	<div class="form-row">
		<label for="node-input-other2"><i class="icon-tag"></i> Other2</label>
		<input type="text" id="node-input-other2">
	</div>
</script>

<script type="text/html" data-help-name="lower-case">
    <p>A simple node that converts the message payloads into all lower-case characters</p>
</script>

My flow:

[
    {
        "id": "837c14c4.912478",
        "type": "inject",
        "z": "ce7e9eec.737d7",
        "name": "",
        "topic": "",
        "payload": "ASD",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 870,
        "y": 620,
        "wires": [
            [
                "32607343.66f30c"
            ]
        ]
    },
    {
        "id": "646d4345.008bac",
        "type": "debug",
        "z": "ce7e9eec.737d7",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 1210,
        "y": 620,
        "wires": []
    },
    {
        "id": "32607343.66f30c",
        "type": "lower-case",
        "z": "ce7e9eec.737d7",
        "name": "",
        "other1": "1",
        "other2": "2",
        "x": 1030,
        "y": 620,
        "wires": [
            [
                "646d4345.008bac"
            ]
        ]
    }
]

I suggest looking at how some other nodes do it.

You need to handle the input from the msg to override the settings if that's what you want.

Hi Sadettin,
I haven't tried your code, but shouldn't you do something like this:

node.on('input', function(msg) {
   msg.payload = msg.payload.toLowerCase();
   msg.other1 = node.other1;
   msg.other2 = node.other2;
   node.send(msg);
}

Because you seem to send a string to the output, instead of a Javascript object...
Bart

You are totally right :slight_smile: Trying your code helped me do what I wanna do. Thanks.

1 Like

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