After the first run: msg.downloadIndex = [0,1]
After the second run: msg.downloadIndex = [0,1,0,1]
After the third run: msg.downloadIndex = [0,1,0,1,0,1]
... I think you get it.
I want that msg.downloadIndex always looks like the first run, after a run.
Let me check to see if I've understood what you are doing:
You have a flow that is triggered at 10 in the morning every day
That flow will cause, in some way, multiple messages to arrive at that Function node and you want to build up an array of the individual msg.parts.index properties from those messages.
The fact you are using msg.parts.index suggests you are using a Split node, or maybe a CSV node to generate a message sequence.
Would it be true to say the first message the Function receives each morning will have msg.parts.index set to 0? If so, you could use that as the hint to the Function node to reset the array:
var local = context.get('data') || [];
if (msg.parts.index === 0) {
local = [];
}
...
If not, then another approach would be to change your node to use Flow Context rather than the local node context - ie swap context.get/set for flow.get/set. You could then add a Change node after the Inject node that kicks things off to set flow.data to [] before the rest of flow is triggered.
I already switched to flow instead of context. And I also reset the flow at tghe beginning, like you proposed. I was just wondering, if there is a more elegant way to do those things.
The more elegant way may be to avoid using context completely. What you are doing seems rather odd so I wonder whether there is a better way to solve whatever the problem is. If you wanted to explore that then if you told us what the larger problem is we may be able to suggest alternatives.
Oh this was kind of an approval to what you were saying.
In the meantime I switched my Flow so that I do not need any flow or context.
thank you for your help