Using $moment() in change node jsonata 'Test' results in an error

In the change node, if you are using JSONata and use the $moment() function and try to test it, you get an error

Error evaluating expression:
  Attempted to invoke a non-function

Bug (?) or is this just something you can't use in the 'Test' portion?

What I want to do is deal with an object in this format:

[
    {
        "time": 1608813423311,
        "humidity": 36.7
    },
    {
        "time": 1608813423511,
        "humidity": 35.5
    }
]

and return the times as hh:mm am/pm

Hi
try

payload ~> |[*]|{"time":$moment(time).tz("london/europe").format("hh:mm a")}|	

That's it... We don't have the moment library loaded in the editor, so just like the context functions, you can't use it in the test panel

Should probably have a message display as we do for the context functions.

@E1cid thanks for the effort but that gives me a
"Invalid JSONata expression: Argument 1 of function undefined does not match function signature"
message. I'm just going to use a function so I'll be able to understand it in the future :crazy_face:

Strange, as working here

Try this flow

[{"id":"4c8fe74d.23b62","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[     {         \"time\": 1608813423311,         \"humidity\": 36.7     },     {         \"time\": 1608813423511,         \"humidity\": 35.5     } ]","payloadType":"json","x":160,"y":2380,"wires":[["6040a378.a42784","84c9d74a.048ca8"]]},{"id":"6040a378.a42784","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload ~> |[*]|{\"time\":$moment(time).tz(\"london/europe\").format(\"hh:mm a\")}|\t\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":2380,"wires":[["84c9d74a.048ca8"]]},{"id":"84c9d74a.048ca8","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":2280,"wires":[]}]

My bad, I put it in the wrong place in my flow after a csv node. it works great!

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