Delete whole msg

Hi,

I find myself needing to reset a msg completely inline with a flow. While I could use a function node, it seems a bit of an oversight not to be able to do this with a change node.

The idea would be to have a drop-down called "Reset msg". It would only really make sense to put it as the first entry of course (unless saving some msg content to a flow variable for later use) but still it would be really useful. Especially since you may not always be able to fully predict all of properties on a msg.

An alternate would be to allow wild-cards in the msg property name. so that you could have something like msg.*. In fact, that would be even more useful, especially if you could do something like msg.xxxx* to delete a bunch of similarly named properties.

Instead of a wildcard, you could have a regex.

Yet another potential option might be to allow a JSONata expression for the delete option where you return an array of entries.

3 Likes

Being able to have a "start over" node, I like - good call, I like it!

for now, I whipped up this. (I am adventurous this evening :blush:)

[{"id":"99b68b4208b45e2f","type":"subflow","name":"Reset MSG","info":"","category":"","in":[{"x":50,"y":30,"wires":[{"id":"44c96ae25491502b"}]}],"out":[{"x":320,"y":135,"wires":[{"id":"44c96ae25491502b","port":0}]}],"env":[],"meta":{},"color":"#C0C0C0","icon":"font-awesome/fa-close"},{"id":"44c96ae25491502b","type":"function","z":"99b68b4208b45e2f","name":"function 2","func":"msg = {}\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":165,"y":120,"wires":[[]]},{"id":"d25df8c32a9f06ba","type":"subflow:99b68b4208b45e2f","z":"2d7bf6e3.84c97a","name":"","x":300,"y":645,"wires":[["2fbc2f4203a938d1"]]},{"id":"8d675faadefabfaa","type":"inject","z":"2d7bf6e3.84c97a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":645,"wires":[["d25df8c32a9f06ba"]]},{"id":"2fbc2f4203a938d1","type":"debug","z":"2d7bf6e3.84c97a","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":495,"y":645,"wires":[]}]

Well yes, that is one way. :smiley:

Feels a bit overkill though. I don't think that it would be much to add to the delete option of the change node.

But thanks, I can obviously use your subflow for now. Though you can simplify it further:

return {}

:wink:

1 Like

But I do agree, being able to Nuke the object will be a nice addition in a change Node.
I did try tricking it, but nope, it wasn't happening

1 Like

Am I missing something, if I need to clear a message path, I set the message to an empty object.

That is the same message, the second was sent through a change node.

Yes - we get that.

But to clear the object, one needs to use a function node currently, without getting into the weeds...
This involves creating a Javascript Virtual Machine (that the function nodes creates), and this creates overheads in doing so - I believe

The change node, has the ability to manipulate the object (msg) - without creating a VM, and the suggestion here is to extend the ability to clear the object, without creating a VM.

Note: this is about the whole msg object, not a property inside of it (like payload). -which is a property

3 Likes

This was discussed a few years back Add a way to create a completely new object (change node enhancement?)

2 Likes

Hmm, well spotted. But that seems to have been massively over-thought.

Node-RED automatically recreates the msg id as far as I can tell and if I'm asking to delete the whole msg, there has to be an expectation that this is what I really want.

So I don't think that any of the other properties should be kept.

If necessary, there should be 2 different options:

  • Delete all the msg content - just nukes all the content.
  • Reset the msg content - which retains the things that Dave and Nick were referring to.

Obviously, the former is easier to implement.

2 Likes

This would be a welcome addition, i often encounter this issue when using http request/sql nodes where properties live outside payload.

However, somewhere I would like to keep a single or multiple properties but remove the rest. Currently, i am delete all individual properties which is cumbersome.

3 Likes

To add my bit,

Sometimes I think I have been in a similar/same situation and it would be handy.

As stated, I use a function node to create a new message.
(sorry, I'm rambling now.)

But I do agree it would be a nice thing to have.

I did think about an option that would take an array of properties to remove. That could also be nice.

Obviously, there is a danger here of going down too many rabbit holes again. So trying to keep ideas simple, at least for now.

I know I'm going to regret this, but I've never actually done a PR for Node-RED as I've always been put off by the complexity as well as my lack of knowledge of how to do test scripts. But maybe this might be the time?

Would welcome some confirmation from the core devs though before trying to continue.

I did create a node node-red-contrib-remap that may help. Configuration is usually a two step process, but it can be set to block all or pass all by default. Once you have run it once you can then configure it to pass, remove, or remap individual properties.

1 Like

And I even have that installed on my dev instance but not live! Thanks for the reminder Dave. I've now added it to my flows collection of useful nodes. :slight_smile: