Change node, modify message property

I know I have asked before, but can't remember the exact wording.

Only to save using nodes, I want to change a message property in a change node.

So what I want to do:

I am getting msg.delay and multiply it by 1000.

I know I have to enter it in the J: expression part, but.... That's the limit.

I'll try a could of things, but I know the system is if I don't ask I won't remember.
If I do ask, before I get an answer the probability of me remembering will go up.

Remembered:

msg.delay = msg.delay * 1000

Couldn't really be easier.

Please explain how the above expression is the solution to modifying msg.delay in a change node?

Using that expression in a change node will modify the property value to false, it will not multiply it by 1000.

Use delay * 1000 in the JSONata expression.

What you posted will work in a function node, but your question was for a change node. I had to say something as your solution may confuse others looking for a solution to modifying in a change node.

[{"id":"b95ccd5.63ef1b","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"delay","v":"4","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":1940,"wires":[["70ea60b1.134808"]]},{"id":"70ea60b1.134808","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"delay * 1000","tot":"jsonata"},{"t":"set","p":"delay","pt":"msg","to":"msg.delay = msg.delay * 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1940,"wires":[["be48273.628c958"]]},{"id":"be48273.628c958","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":560,"y":1940,"wires":[]}]

In fairness, Andrew did say...

I fail to see your point. Entering a Javascript expression into a JSONata expression box still will not work, and the solution is confusing to other users.

Sorry, yes, you are right, I am assuming (since he said it works) that he didnt actually put msg.delay = msg.delay * 1000 into the expression (as it wouldnt work). I read this as he set msg.delay to msg.delay * 1000 using J: expression.

but yes, you are right to clarify - it is a bit unclear for those not reading between the lines.

To clarify msg.delay * 1000will not work either.

It does.

image

image

[{"id":"e71f4e83.15362","type":"inject","z":"f77cda4d.5d7628","name":"delay: 2","props":[{"p":"payload"},{"p":"delay","v":"2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1190,"y":260,"wires":[["464da612.cf3418"]]},{"id":"464da612.cf3418","type":"change","z":"f77cda4d.5d7628","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.delay * 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":300,"wires":[["ff13eed3.37ddd"]]},{"id":"ff13eed3.37ddd","type":"debug","z":"f77cda4d.5d7628","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1230,"y":340,"wires":[]}]

Apology, It does indeed work. I never use msg in JSONata as it is not needed.

No its not, but if memory serves, it is there for backwards compatibility.

Wow.... Ok.

I am using the change node and I needed to change things.

This is the part of the flow in question:

[{"id":"7f22aa5b.695bbc","type":"ui_slider","z":"ae12fd.00ef75","name":"Sydney","label":"Frequency (m)","tooltip":"","group":"ebcaab30.c904b","order":2,"width":3,"height":1,"passthru":false,"outs":"end","topic":"","min":"1","max":"30","step":1,"x":420,"y":3820,"wires":[["4acbf31d.4b45b4"]]},{"id":"4acbf31d.4b45b4","type":"change","z":"ae12fd.00ef75","name":"convert to minutes","rules":[{"t":"move","p":"payload","pt":"msg","to":"delay","tot":"msg"},{"t":"set","p":"delay","pt":"msg","to":"msg.delay * 60000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":525,"y":3820,"wires":[["110b9f17.9c9241"]],"l":false},{"id":"110b9f17.9c9241","type":"trigger","z":"ae12fd.00ef75","name":"Variable","op1":"trigger","op2":"0","op1type":"str","op2type":"str","duration":"-30","extend":false,"overrideDelay":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":630,"y":3820,"wires":[["f57d4697.23dda"]]},{"id":"ebcaab30.c904b","type":"ui_group","name":"Sydney weather","tab":"de0f6b36.132fa8","order":2,"disp":true,"width":"8","collapse":false},{"id":"de0f6b36.132fa8","type":"ui_tab","name":"Weather","icon":"dashboard","order":17,"disabled":false,"hidden":false}]

The slider node outputs msg.payload and I need it to be msg.delay to adjust the delay time on the trigger node.

But I don't want to send numbers that big to control the delay/repeat time from 1 minute to 30 minutes.

So, the change node moves msg.payload to msg.delay. (Line 1)
(Line 2) multiplies msg.delay by 60000 to make the number for minutes.

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