1

I am trying to insert in node multiples values to the Azure Storage Table but only the last value is added. Is it something related to node synchronous or asynchronous mode (I am newbie in node)?

    Code snippet:

...

for (var i = 0; i < 21; i++) { 
    var emissao = newData[keys[i]].emissao;
    var codigoProduto = newData[keys[i]].codigoProduto;
    var quantidade = newData[keys[i]].quantidade;

    context.bindings.outputTable = {
        "PartitionKey": "08755044001539",
        "RowKey": i.toString(),
        "Emissao": emissao,
        "CodigoProduto": codigoProduto,
        "Quantidade": quantidade
    }
}

context.done();

project.json

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */5 * * * *"
    },
    {
      "type": "table",
      "name": "outputTable",
      "tableName": "outTable",
      "connection": "detfunction9451_STORAGE",
      "direction": "out"
    }
  ]
}

1 Answer 1

2

Should you be adding records to the outputTable, instead?

context.bindings.outputTable.push({
  "PartitionKey": "08755044001539",
  "RowKey": i.toString(),
  "Emissao": emissao,
  "CodigoProduto": codigoProduto,
  "Quantidade": quantidade
});

This may mean you have to initialize the outputTable first. I'm not sure. This may be necessary:

context.bindings.outputTable = [];

for (var i = 0; i < 21; i++) { 
  var emissao = newData[keys[i]].emissao;
  var codigoProduto = newData[keys[i]].codigoProduto;
  var quantidade = newData[keys[i]].quantidade;

  context.bindings.outputTable.push({
    "PartitionKey": "08755044001539",
    "RowKey": i.toString(),
    "Emissao": emissao,
    "CodigoProduto": codigoProduto,
    "Quantidade": quantidade
  });
}

context.done();

Here's an example from Microsoft.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.