Insert a variable into a change node

hi!
I have a http request that has a json in it's response. so far so normal. but one of the objects inside the json has a different name depending on what I sent into the http request.

I have a drop down in a dashboard. when I select one item it triggers the http request and then the same value of the drop down shows up in the json structure.

then I take the response and using change nodes I fill text fields in the dashboard.
my question: how do I get the value of the dropdown in my json path

change

If you add the value to the message that is sent to the http node in a new property, something like msg.dropDown possibly, then that should get passed straight through the http node as nodes should always try to keep extra parameters in the passed in message. Then you can use it in your change node. Note that it must be a separate property of msg, not in the payload. I have to admit that I have not tried it with the http node though. It would be easy to test by adding a test Change node before the http node, adding some fixed text in msg.dropDown and seeing what comes out. Use a debug node set to Show Complete Message to check if it is still there in the response message.

hey! that's actually working. so if I add a function after the dropbox in the flow and add a msg.DropBox, I can display the value auf msg.DropBox in a text on my dashboard, after the http request.

BUT when I use it in my change node it doesn't work. maybe that's a syntax issue.

msg.payload[msg.DropBox].SOC is not working

In the change node selett the jsonata option then use the expression
payload[$$.DropBox]
and see if that works.

here is a simple inject->change->debug flow using msg.array as the array and msg.topic as the index value:

[{"id":"2517e138.caf176","type":"debug","z":"7abfc37c.974ed4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":190,"y":180,"wires":[]},{"id":"65582247.f6b41c","type":"inject","z":"7abfc37c.974ed4","name":"","props":[{"p":"array","v":"['cat','dog','frog']","vt":"jsonata"},{"p":"topic","v":"2","vt":"num"},{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":60,"wires":[["d24362d7.3109a8"]]},{"id":"d24362d7.3109a8","type":"change","z":"7abfc37c.974ed4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"array[$$.topic]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":120,"wires":[["2517e138.caf176"]]}]

I'm a noob...I don't get it.

I somehow have to change a piece of the payload path with the value of a msg Key

I have the msg.payload from the http request and the msg.DropBox from my dropBox.

and the payload json has at one level the DropBox value.

{"success":true,
"total":1,
"msg":null,
"count":null,
"vehicles":
{"LC06S44R7L4000052":
{"Total Mileage":"584.0","Battery Temperature":"20","Driving Range":"260.0","SOC":"94","Time":"2020-09-10 11:23:05","Location":{"Latitude":"51.446148","Longitude":"7.196758"}}
}
}

where the LC06S44R7L4000052 is the dynamic part and this name is in my msg.DropBox
And so the get the "Total Mileage" displayed in my text field I need to access msg.payload.verhicles.LC06S44R7L4000052["Total Mileage"] but the LC part replaces with my msg.DropBox

found the solution. storing the math in a variable and then using eval

so I have a function

var path = "msg.payload"+msg.Dropbox+".SOC"
msg.payload = eval (path)
return msg;
1 Like

In the image you provided you had ..d.vehicles[myDropDownValue].SOC so I thought it was an array you were trying to index into.

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