How should the change node work with context?

Using the change node to modify several properties of an incoming message, I decided to save the modified message in global context. It took a while to find the trick, but this seems to work.

But I have questions. Should this even work? Or is it a quirk of the JSONata compatibility mode that will go away someday? Can the change node do the reverse, that is retrieve the message from context and send it on? (I haven't found a way, so far.)

Try setting to global.msg0!

Not exactly, but my question wasn't completely clear. That retrieves the old message as a property of the incoming message, not as a message itself that can be sent along.

But all properties are "Sent along" as part of the parent msg.

Understood, but what I really want is the equivalent of a function with

return global.get("msg0");

so that I get back exactly the message that I saved in context.

OK, can I ask why you want to do that?

Just to answer the original question, the Change cannot set the entire message object. Not an intentional restriction - just never had a requirement to be able to do it.

1 Like

I had forgotten that this has been discussed before. Clearly, there are some technical issues involved, but there seem to be other users who might like to have the feature.

At the moment, I'm just exploring the possibilities. I'm working on a couple of projects involving fairly complex message routing -- distribution, queueing, load balancing, etc. and I'm making a sort of catalogue of the available tools (including my contributed nodes, of course).

Nick, if you don't mind another question, will the configuration in the screenshot continue to work, or does it depend on the compatibility mode for JSONata?

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