0

I have an array with some Objects that I would like to send to a azure queue. I have a simple array with some data and a for that goes trough each element of the array and push it to the queue. Everything goes smooth but when I see the queue I can find only the last member of the array and not all the objects.

My code looks like this:

module.exports = async function (context, myQueueItem) {
var tabdata = []
tabdata =(
{housecode:1,car: 2, familymbembers:5,status:"Error"},{housecode:2,car: 5, familymbembers:4,status:"normal"},{housecode:3,car: 2, familymbembers:4,status:"Error"})


//does some other stuff


   for (let i = 0; i < tabData.length; i++) {
        if(tabData[i].status == "Error"){
            context.bindings.outputQueueError = (tabData[i]);

        }
        
    }
context.done();
}

If I try to print the objects after the context.bindings.output I can see that the for and the if are working correctly(I get printed the 0 and 2 object in the array), but in the queue I Can see only the one object with house code 3.

Any help?

varVal
  • 27
  • 7

2 Answers2

0

Your problem is with this line of code

context.bindings.outputQueueError = (tabData[i]);

On the first iteration of the loop the logical expression is true, and you assign that value to context.bindings.outputQueueError. Then, on the last iteration, you assign that value to context.bindings.outputQueueError.

Looks like you need to send to the azure queue inside the iteration block for each object that passes the expression, or push to an array inside that for loop and send each object to the queue elsewhere.

cWerning
  • 583
  • 1
  • 5
  • 15
  • hello, I've used another method (sending array of messages) and it works, thank you for your answer – varVal Dec 15 '20 at 14:33
0

Fixxed with using an array of messages

module.exports = function(context) {
    context.bindings.myQueueItem = ["message 1","message 2"];
    context.done();
};
varVal
  • 27
  • 7