# Format variable with string + variable in change node

**URL:** <https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724>\
**Category:** General\
**Created:** [3 February 2022 13:37 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724 "2022-02-03T13:37:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhjensen79](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rhjensen79/32/55717_2.png) [@rhjensen79](https://discourse.nodered.org/u/rhjensen79)\
**Post date:** [3 February 2022 13:37 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/1 "2022-02-03T13:37:25Z")

</div>

Hi.

In a function node, i can create :  
msg.payload.accessToken = "Bearer "+ msg.payload.accessToken;

when i wan't to combine a string + variable.  
But is there a way to do the same in a change node.  
There seams to be a lot of option the the change node, but i can't quite figure out how to do this.

Thanks

/Robert

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 February 2022 13:51 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/2 "2022-02-03T13:51:33Z")

</div>

> [@rhjensen79](#):
>
> But is there a way to do the same in a change node

Yes, if you use JSONata.  
set `msg.` `payload.accessToken`  
to the value of `"Bearer " & payload.accessToken`

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [3 February 2022 13:51 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/3 "2022-02-03T13:51:51Z")

</div>

Welcome to the forum!

Try this in a change node, using JSONata.  
 ![Screenshot-39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/a/9ad689887bf1fdc5937bce3a0374be330df529c1.png)

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [3 February 2022 13:52 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/4 "2022-02-03T13:52:31Z")

</div>

@Steve-Mcl beat me to it!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 February 2022 13:52 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/5 "2022-02-03T13:52:52Z")

</div>

snap 😃

Great minds & all 😉

---

<div class="post-metadata">

**Author:** ![rhjensen79](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rhjensen79/32/55717_2.png) [@rhjensen79](https://discourse.nodered.org/u/rhjensen79)\
**Post date:** [3 February 2022 13:54 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/6 "2022-02-03T13:54:21Z")

</div>

Damn you guys are fast 🙂

Thanks. That's really easy. 🙏

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [3 February 2022 13:55 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/7 "2022-02-03T13:55:15Z")

</div>

Steve,  
I think that in terms of node-red knowledge then: @Steve-Mcl \> @ghayne🙂

---

<div class="post-metadata">

**Author:** ![rhjensen79](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rhjensen79/32/55717_2.png) [@rhjensen79](https://discourse.nodered.org/u/rhjensen79)\
**Post date:** [3 February 2022 14:35 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/8 "2022-02-03T14:35:32Z")

</div>

Sorry but i have to ask again.

Took it a bit further, but the variable does not get reconized, so the result is 2 combined strings, without the variable.

I'm setting a global variable somewhere else in my job to global.id using another change node.

in the combine job i'm trying :

"[https://api.easee.cloud/api/chargers/](https://api.easee.cloud/api/chargers/)" & global.id & "/state"

But the global.id is just empty.

Any idea on what i'm doing wrong.

And thanks in advance 🙂

---

<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:** [3 February 2022 14:40 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/9 "2022-02-03T14:40:40Z")

</div>

You failed to mention `global.id` is that a context global called id. If so it would be `globalContext("id")`.

---

<div class="post-metadata">

**Author:** ![rhjensen79](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rhjensen79/32/55717_2.png) [@rhjensen79](https://discourse.nodered.org/u/rhjensen79)\
**Post date:** [3 February 2022 15:24 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/10 "2022-02-03T15:24:23Z")

</div>

> [@E1cid](#):
>
> globalContext("id")

Thanks. That was the error.  
I had to set a $ in front, to make it work.

But it's working like this :  
"[https://api.easee.cloud/api/chargers/](https://api.easee.cloud/api/chargers/)" & $globalContext("id") & "/state"

---

<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:** [17 February 2022 15:24 UTC](https://discourse.nodered.org/t/format-variable-with-string-variable-in-change-node/57724/11 "2022-02-17T15:24:37Z")

</div>

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