How to access a message variable while using a JSONata expression in a change node?

Hi all,

I'm trying to access the value of a message context while using a JSONata expression in a change node, but I can't happen to get it working.

Obviously, no problem with Flow or Global context since the JSON function exists, but how about simple message value ?

I would keep getting the following error:

image

To add on,

I have therefore tried to generate a flow variable instead, but the change node would reject the syntax :

And I don't want to have to use static decimal number such as 0, 1, 2, etc. as it makes my code way too static.

Try something like below

$flowContext("blah.blah[" & $$.cueindex & "].balh")

Still not working :frowning:

I see no & or quotes closing the string

Oh my god sorry I was too excited to try... haha, it seems to be working !!

Thank you so much, I'm gonna continue my testing !!

I see you have mixed up quotes. If you use single then close with single

$flowContext('blah.blah[' & $$.cueindex & '].balh')

as you have shown is still incorrect and a single string no concatenation happens.

Alright, noted, thanks !

Now I'm having another issue in a template node this time.

I need to use that message variable inside an array, which is inside a flow message as follows.

But msg.cueIndex does not work:

Neither $$.cueIndex, nor {{cueIndex}}, nor {{msg.cueIndex}}

Any idea ?

First template node does not use [ ] for arrays.
Second , i don't think that is possible in the template node. Best create a msg property from the flow var prior to the template node.

Or you could do your template in a change node with JSONata.

If I use single quotes everywhere, I'm getting the error again as follows:

Same, if I use double quotes everywhere, error is still here:

What happens if you
set msg.payload to
'blah.blah[' & $$.cueIndex & '].blah'
what is the output, as it seems from the error it expects something before ], but throws error as it get ] and not what is expected.

Make sure no typo's of cueIndex

The blah being your properties not blah.

please post code as text as i can then copy it.

Thank you so much, got everything working correctly in the JSONata expression of the change node,

But I now need to find the simplest / cleanest way to use this message variable in the flow variable in the template node, best would be to be able to do everything inside.

But if I got no choice, will prepare the data outside in a change node, tho I don't really like the idea... lol

Not knowing the node configuration of your flow makes it difficult to give an definite ideas. in your change node can you not template there by concatenating strings and msg/context vars. Or as said define flow context to a msg var, then you can use the msg var in the template node.

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