# Appending an attribute to an incoming message from a flow context

**URL:** <https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954>\
**Category:** General\
**Created:** [9 December 2021 18:55 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954 "2021-12-09T18:55:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChankyTheConqueror](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chankytheconqueror/32/52296_2.png) [@ChankyTheConqueror](https://discourse.nodered.org/u/ChankyTheConqueror)\
**Post date:** [9 December 2021 18:55 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/1 "2021-12-09T18:55:57Z")

</div>

Hi,  
i'm new here, thank you for the great forum, well i'm playing with interactive ui-tables, and i have this specific table containing my temperature sensors on the same table i have a column which is editable. The column (isUsedForHeating) should configure whether a temperature sensor should be considered when controlling my heating system, e.g i want for instance if a room is not currently used then the heater should not switch on because the temperature is too low in the specific room.

So the attribute "isUsedForHeating" can be edited by a user directly in the table. That is not a problem since i get a callback from the table and i can change the flow context.

My problem is only when a new temperature value is received i cant append the value from the context directly.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e59e9633c1f51850596860e12ad1e3143499513e.png)  
i would imagine to use a change node and do the following:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea8ee087b692ec015aab04162d259e03db2585d8.png)  
but how can i get the \<msg.topic\>, (the device name is unique and passed through msg.topic)? Or what would be the best way to append the attribute from the stored context?

This is the table:

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

I'm a C programmer so please excuse my limited java script skills.

Thanks in advance!

Regards  
ChankyTheConqueror

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 December 2021 20:03 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/2 "2021-12-09T20:03:38Z")

</div>

Hi.

I'm no expert, but here's a try.

Looking at what you said I think I understand what you mean.

You get the incoming message and pass it through a `change` node to set part of the message to a `flow.context` value.

That part is editable on the table as shown above.

So what is it you then want to do?

Maybe a screen shot of that part of the flow would help too. (Not all of it)

Is it you want the column that is labelled as "Used for heating" to be the `topic` value?

---

<div class="post-metadata">

**Author:** ![ChankyTheConqueror](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chankytheconqueror/32/52296_2.png) [@ChankyTheConqueror](https://discourse.nodered.org/u/ChankyTheConqueror)\
**Post date:** [9 December 2021 20:46 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/3 "2021-12-09T20:46:49Z")

</div>

Hi,  
Yes i want to pass it through a change node and append the attribute. I think i'm almost there i just need a little push. Here is what im currently trying with Jsonata but im getting an invalid expression:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a18b15abb6d46b432d455accf3f6236810c6356.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc1b4f6ecef8d97dc4c701c2f79e31dd7bb82c29.png)

this is my flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8dfacd0649e535fbe9ed2835da2fc125a0b523ef.png)  
this is my flow context:

```auto
{
    "zTempSensRobin": {
        "device": "zTempSensRobin",
        "battery": 57,
        "humidity": 53.82,
        "last_seen": 1639081831131,
        "linkquality": 144,
        "pressure": 959,
        "temperature": 21.33,
        "voltage": 2925,
        "roomName": "Robin's room",
        "lowBattery": false,
        "lastSeen": "09/12/2021 22:30",
        "isUsedForHeating": true
    }
}

```

Thanks

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 December 2021 20:54 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/4 "2021-12-09T20:54:13Z")

</div>

You may need to use the `JSON` node just after the node that receives the temperature.

---

<div class="post-metadata">

**Author:** ![ChankyTheConqueror](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chankytheconqueror/32/52296_2.png) [@ChankyTheConqueror](https://discourse.nodered.org/u/ChankyTheConqueror)\
**Post date:** [9 December 2021 20:57 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/5 "2021-12-09T20:57:03Z")

</div>

I'm not sure i understand what you mean, do you mean instead of the change node i should use a JSON node?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 December 2021 20:59 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/6 "2021-12-09T20:59:49Z")

</div>

Sorry. I may be wrong.

Just to establish what is going on, please put a debug node (set to show the entire message content) on the output of the node who's message we are looking.

This way we can see what the message looks like and work from there.

(I was meaning to put a `JSON` node between that blue node before the `change` node.)

---

<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:** [9 December 2021 21:05 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/7 "2021-12-09T21:05:51Z")

</div>

Try

```auto
$flowContext("tableData." & topic & ".isUsedForHeating")

```

---

<div class="post-metadata">

**Author:** ![ChankyTheConqueror](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chankytheconqueror/32/52296_2.png) [@ChankyTheConqueror](https://discourse.nodered.org/u/ChankyTheConqueror)\
**Post date:** [9 December 2021 21:17 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/8 "2021-12-09T21:17:20Z")

</div>

This is an incoming message

```auto
{
    "topic": "zTempSensRobin",
    "qos": 0,
    "retain": true,
    "_msgid": "79dfd26beb15a90a",
    "state": {
        "battery": 57,
        "humidity": 54.79,
        "last_seen": 1639084512516,
        "linkquality": 147,
        "pressure": 959,
        "temperature": 21.44,
        "voltage": 2925,
        "roomName": "Robin's room",
        "lowBattery": false,
        "lastSeen": "09/12/2021 23:15",
        "device": "zTempSensRobin"
    }
}

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 December 2021 21:18 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/9 "2021-12-09T21:18:01Z")

</div>

Thanks.

I think I shall defer to what @E1cid said as a possibility to fix the problem.

---

<div class="post-metadata">

**Author:** ![ChankyTheConqueror](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chankytheconqueror/32/52296_2.png) [@ChankyTheConqueror](https://discourse.nodered.org/u/ChankyTheConqueror)\
**Post date:** [9 December 2021 21:19 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/10 "2021-12-09T21:19:53Z")

</div>

> [@E1cid](#):
>
> ```auto
> $flowContext("tableData." & topic & ".isUsedForHeating")
> 
> ```

it works now thanks alot what a great forum!

---

<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:** [23 December 2021 21:20 UTC](https://discourse.nodered.org/t/appending-an-attribute-to-an-incoming-message-from-a-flow-context/54954/11 "2021-12-23T21:20:30Z")

</div>

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