Format variable with string + variable in change node

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

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

Welcome to the forum!

Try this in a change node, using JSONata.
Screenshot-39

1 Like

@Steve-Mcl beat me to it!

1 Like

snap :smiley:

Great minds & all :wink:

1 Like

Damn you guys are fast :slight_smile:

Thanks. That's really easy. :pray:

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

2 Likes

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/" & global.id & "/state"

But the global.id is just empty.

Any idea on what i'm doing wrong.

And thanks in advance :slight_smile:

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

1 Like

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/" & $globalContext("id") & "/state"

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