Increment/decrement property using core nodes

It would, at least, be more consistent. It would need adding to JSONata as well though wouldn't it - or is it already accessible there, I can't remember.

not sure how local context would help in this instance as unless the constant to be added/subtracted was sent on the previous message it would then get overwritten by the new message reseting the context. (but maybe again it's Friday and I'm missing something). I think the idea of a separate numbers only Maths node is probably the right one.

1 Like

I could see how you could have something like the change node to build up an operation from msg.property/context.var/constant value/list of operations.
Then ability to add another operation, but this would require some thought about where the ongiong result is held. As after number of operations it could become difficult to follow.

Provided the stuff you want to run repeatedly does not trash msg properties that do not concern it (which it shouldn't) then you can do it like this:

[{"id":"c9ef69f62e5ac84b","type":"inject","z":"bdd7be38.d3b55","name":"Go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":90,"y":2880,"wires":[["56855bac6915ad22"]]},{"id":"56855bac6915ad22","type":"change","z":"bdd7be38.d3b55","name":"Clear msg.count","rules":[{"t":"set","p":"count","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":2880,"wires":[["69479cd5a15f4e13"]]},{"id":"e8e2b9984d4983df","type":"switch","z":"bdd7be38.d3b55","name":">=10?","property":"count","propertyType":"msg","rules":[{"t":"gte","v":"10","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":2880,"wires":[["d0d6cf5ab587798c"],["7c136523ddcea5bc"]]},{"id":"7c136523ddcea5bc","type":"change","z":"bdd7be38.d3b55","name":"Increment msg.count","rules":[{"t":"set","p":"count","pt":"msg","to":"count+1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":2960,"wires":[["dc3b9bf2c42edf87","69479cd5a15f4e13"]]},{"id":"dc3b9bf2c42edf87","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":2960,"wires":[]},{"id":"69479cd5a15f4e13","type":"delay","z":"bdd7be38.d3b55","name":"Do stuff","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":440,"y":2880,"wires":[["e8e2b9984d4983df"]]},{"id":"d0d6cf5ab587798c","type":"debug","z":"bdd7be38.d3b55","name":"DONE","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":2880,"wires":[]}]

:slight_smile:
Although its code - it's pretty much minimal :slight_smile:
image

I suppose you could use a flow variable by doing it like this

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