# Get value of numeric input node

**URL:** <https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673>\
**Category:** Dashboard\
**Created:** [10 November 2020 12:45 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673 "2020-11-10T12:45:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenrdP](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BenrdP](https://discourse.nodered.org/u/BenrdP)\
**Post date:** [10 November 2020 12:45 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/1 "2020-11-10T12:45:44Z")

</div>

Hello,

I have different input fields and I want to read out the content each second.  
I used the "get state" node to trigger the reading for each second together with a "function node".

With the following content this works perfect for the my "switch nodes"

var state = context.get('state') || false;  
if (msg.topic == 'switch11') {  
state = msg.payload;  
context.set('state', state);  
}  
if (msg.payload == 'get state') {  
return {payload: state};  
}  
return;

But for my "numeric input" node and also for the "dopdown" node , I could not found a corresponding solution for the content of the "function node" until now.

Bernd

---

<div class="post-metadata">

**Author:** ![BenrdP](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BenrdP](https://discourse.nodered.org/u/BenrdP)\
**Post date:** [10 November 2020 15:48 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/2 "2020-11-10T15:48:57Z")

</div>

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

This is working with the shown function content

---

<div class="post-metadata">

**Author:** ![BenrdP](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BenrdP](https://discourse.nodered.org/u/BenrdP)\
**Post date:** [10 November 2020 15:51 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/3 "2020-11-10T15:51:33Z")

</div>

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

For these two flows I cannot get the correct funtion.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 November 2020 18:55 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/4 "2020-11-10T18:55:49Z")

</div>

Put a debug node on the outputs of the 'switch11', the 'get state', the 'ui\_numeric' and the ui\_dropdown' nodes and look at what msg.payload looks like coming from each one.

Next compare that with your function node to see how the function will work with that data.

---

<div class="post-metadata">

**Author:** ![BenrdP](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BenrdP](https://discourse.nodered.org/u/BenrdP)\
**Post date:** [10 November 2020 21:14 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/5 "2020-11-10T21:14:07Z")

</div>

**Correct working switch**

ui\_switch sends nothing out, but content is e.g. true.  
get state sends out "get state" each second  
state function sends out true each second

**Not working numeric input**  
ui\_numeric sends nothing out, but content is e.g. 30  
get state sends out "get state" each second  
state function should send out 30 each second but I until now have not found the correct function code to have access to the numeric value

---

<div class="post-metadata">

**Author:** ![BenrdP](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BenrdP](https://discourse.nodered.org/u/BenrdP)\
**Post date:** [10 November 2020 21:21 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/6 "2020-11-10T21:21:33Z")

</div>

I have checked again, the switch flow is also working without the connection from switch to the funtion node.

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [10 November 2020 21:25 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/7 "2020-11-10T21:25:19Z")

</div>

`if (msg.topic == 'switch11') {`

If you did copy the function node, have you checked what is the topic you sending from `ui_numeric` or from `ui_dropdown` nodes. Cos if those are different, the function will not save new value to context.

---

<div class="post-metadata">

**Author:** ![BenrdP](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BenrdP](https://discourse.nodered.org/u/BenrdP)\
**Post date:** [10 November 2020 23:57 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/8 "2020-11-10T23:57:28Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/395ad3bfdbb3523d347876c383798bfa4934fe00.png)

With the following function ( I modified the function from the working switch) content I only get false and not the numeric content.

var state = context.get('value') || false;  
if (msg.topic == 'numeric') {  
state = msg.payload;  
context.set('value', state);  
}  
if (msg.payload == 'get value') {  
return {payload: state};  
}  
return;

---

<div class="post-metadata">

**Author:** ![BenrdP](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BenrdP](https://discourse.nodered.org/u/BenrdP)\
**Post date:** [11 November 2020 00:10 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/9 "2020-11-11T00:10:58Z")

</div>

I was wrong, numeric have to be connected to the function-node. I tested all in an extra small flow and now it works

---

<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:** [25 November 2020 00:11 UTC](https://discourse.nodered.org/t/get-value-of-numeric-input-node/35673/10 "2020-11-25T00:11:24Z")

</div>

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