Use variable as an index to udpate flow array object

image

I have a flow array "apgroupSelection" and declare that in the 1st function (left) node context using:

apgroupSelection = flow.get("apgroupSelection");

I go through a loop and push data into the array using:

pgroupSelection.push({id: flow.get("apgroupName"),groupId: flow.get("apgroupID"),threshold: flow.get("threshold"),alert: false});

Each time I push the data in the 1st function node I also send an HTTP request and then do some processing in the 2nd function node. From the 1st function node I also send msg.loopCounter = <loopCounter value> to the 2nd function node so it knows which array index is currently being processed.

In the 2nd function node I want to update the value of "alert:" directly in the flow array using the loopCounter as the array index, rather than having to declare the flow array in context each time this function node is called. Tried the parameters below:

flow.set("apgroupSelection[msg.loopCounter].alert", true);

Also tried declaring loopCounter as a variable and just using [loopCounter], and tried [+loopCounter] without success. It seems to expect only a numeric index number in [ ] not a variable?

Anyway to achieve what I'm trying to do without having to declare the array in the 2nd fucntion node each time I call this function?

flow.set("test["+msg.payload+"].count",msg.payload)
just tested and the above works for me. payload is a number.

Hello and thx for your super-quick repsonse. I just used a variation of your answer to fit my parameters below and it now work great :+1:

flow.set("apgroupSelection[" + loopCounter + "].alert", true);

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