# How to make a created node's property accept dynamic (msg) values

**URL:** https://discourse.nodered.org/t/how-to-make-a-created-nodes-property-accept-dynamic-msg-values/61305
**Category:** Developing Nodes
**Created:** [14 April 2022 18:59 UTC](https://discourse.nodered.org/t/how-to-make-a-created-nodes-property-accept-dynamic-msg-values/61305 "2022-04-14T18:59:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![joaquim.braga](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@joaquim.braga](https://discourse.nodered.org/u/joaquim.braga)
#### Post date: [14 April 2022 18:59 UTC](https://discourse.nodered.org/t/how-to-make-a-created-nodes-property-accept-dynamic-msg-values/61305/1 "2022-04-14T18:59:36Z")

</div>

I created a node that takes a property called tagId

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/15664fb9e83e3cb8a780a980ddb8a4d56b472ac4.png)

The node works fine when I set tagId to a static value.

I want the node to be able to receive either a static value or a value from msg. Something like

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d1c6c9e2ad0a1bb19966c90ba6ed60ba517ad8c7.png)

Is there a way for me to do this? Do I have to change something in my code?

For reference, here is some of my code:  
-------.html-------

```auto
<script type="text/javascript">
    RED.nodes.registerType('rename-tag',{
        category: '----',
        color: '#6aacda',
        defaults: {
            name: {value:""},
            tagId: {value:0},
            newName: {value:""}
        },
        inputs:1,
        outputs:1,
        paletteLabel: "Rename Tag",
        icon: "icon.png",
        label: function() {
            return this.name||"Rename Tag";
        }
    });
</script>

```

-------.js-------

```auto
module.exports = function(RED) {
    function RenameTagNode(config) {
        RED.nodes.createNode(this,config);
        this.tagId = config.tagId;
        this.newName = config.newName;
        var node = this;
        node.on('input', function(msg, send, done) {
            send = send || function() { node.send.apply(node,arguments) }
            ...
            if (done) {
                done();
            }
        });
    }
    RED.nodes.registerType("rename-tag",RenameTagNode);
}

```

Where tagId is the property in question.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [14 April 2022 19:05 UTC](https://discourse.nodered.org/t/how-to-make-a-created-nodes-property-accept-dynamic-msg-values/61305/2 "2022-04-14T19:05:41Z")

</div>

The recommended way is to allow the data to look for and pick up the appropriate msg property if the Editor entry is left blank.

Something like (untested):

```nohighlight
// ...
node.on('input', function(msg, send, done) {
    if ( node.tagId === '' && msg.payload && msg.payload.foo ) node.tagId = msg.payload.fo
    // ...

```

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [14 April 2022 19:10 UTC](https://discourse.nodered.org/t/how-to-make-a-created-nodes-property-accept-dynamic-msg-values/61305/3 "2022-04-14T19:10:47Z")

</div>

The "usual way" to do this is if left blank then it can be set by something - like msg.tagID... in which case you would just test for that in the on input code... (with the property set by the user having priority)  
The newer more flexible way is to maybe make it a typeInput [TypedInput Widget : Node-RED](https://nodered.org/docs/api/ui/typedInput/) - which can then be set to a string (str) or message property (msg) or other type as well - and gives more flexibility of the property that you would accept. For example the base64 node - [node-red-nodes/70-base64.html at master · node-red/node-red-nodes · GitHub](https://github.com/node-red/node-red-nodes/blob/master/parsers/base64/70-base64.html#L13) and Lines 40-43 and the .js file lines 7 and 12 etc...  
Up to you

---

<div class="post-metadata">

### Author: ![joaquim.braga](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@joaquim.braga](https://discourse.nodered.org/u/joaquim.braga)
#### Post date: [18 April 2022 19:22 UTC](https://discourse.nodered.org/t/how-to-make-a-created-nodes-property-accept-dynamic-msg-values/61305/4 "2022-04-18T19:22:37Z")

</div>

Ok so I implemented the second sugestion (TypedInput Widget) and I just wanted to leave some extra information and useful links for people with less experience (such as myself) who are trying to implement this.

[This](https://discourse.nodered.org/t/typedinput-widget/6894) link has a minimal example of the TypedInput Widget's use.

To understand the .js part of this example and how the input is treated differently depending on the selected type, the documentation for the [evaluateNodeProperty](https://nodered.org/docs/api/modules/v/0.20.0/@node-red_util_util.html#.evaluateNodeProperty) function of the RED.util utility helped me a lot as the example provided above does not use the msg type specifically, which needs an extra parameter in the evaluateNodeProperty function (the msg object itself).

@dceejay Thank you for the very fast and concise response which helped achieve exactly what I wanted to do.

---

<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: [2 May 2022 19:22 UTC](https://discourse.nodered.org/t/how-to-make-a-created-nodes-property-accept-dynamic-msg-values/61305/5 "2022-05-02T19:22:51Z")

</div>

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