Why data is doubled, how I can fix it?












0















Good afternoon.



I have required json, which contains the basic template for the layout of Adaptive Cards (bot framework).



Here's this json:






{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"type": "AdaptiveCard",
"speak": "",
"body": [
{
"type": "TextBlock",
"horizontalAlignment": "center",
"text": "Все машины",
"weight": "bolder",
"isSubtle": false
},
{
"type": "TextBlock",
"text": "Внимание, вы вошли в режим тендера.",
"separator": true
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Подтвердить лот(ы)",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "Идет подтверждение ваших лотов, ожидайте!",
"text": "/accept",
"value": "{"x": "bfVal", "y": "from value"}"
}
}
},
{
"type": "Action.Submit",
"title": "Отменить все лоты",
"data": {
"x": "123",
"msteams": {
"type": "messageBack",
"displayText": "Идет отменение ваших лотов, ожидайте!",
"text": "/cancel",
"value": "{"bfKey": "bfVal", "conflictKey": "from value"}"
}
}
}
]
}





I also have a loop that takes data from my source and forms another json from it.






try {
// Pull in the data from Microsoft Graph.
const client = new SimpleGraphClient(tokenResponse.token);
const me = await client.getList();

var i = 0;
while (i < me['value'].length) {
feed = {
"type": "ColumnSet",
"separator": true,
"columns": [
{
"type": "Column",
"width": 1,
"items": [
{
"type": "TextBlock",
"text": "Продукт",
"isSubtle": true
},
{
"type": "TextBlock",
"size": "extraLarge",
"color": "accent",
"text": me.value[i].fields.Good,
"spacing": "none"
},
{
"type": "TextBlock",
"text": "Дата: " + dateFormat(me.value[i].fields.ShipmentDateTime, 'dd-mm-yyyy'),
"spacing": "yes"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": " "
},
{
"type": "Image",
"url": "https://png.pngtree.com/svg/20170614/engine_oil_410031.png",
"size": "medium",
"spacing": "yes"
},
{
"type": "TextBlock",
"text": " ID: " + me.value[i].fields.id,
"value": me.value[i].fields.id
}
]
},
{
"type": "Column",
"width": 1,
"items": [
{
"type": "TextBlock",
"horizontalAlignment": "right",
"text": "RUB",
"isSubtle": true
},
{
"type": "TextBlock",
"horizontalAlignment": "right",
"size": "extraLarge",
"color": "accent",
"text": me.value[i].fields.PricePerTon,
"spacing": "none"
},
{
"type": "Input.Toggle",
"title": "Приобрести лот",
"valueOn": "true",
"valueOff": "false",
"id": "buyGood",
"spacing": "yes"
}
]
}
]
}

tender.body.push(feed);
i++;

}





Then I combine these json.



This works well, but when you retrieve the data again, the data is doubled.



How can this be resolved?



Thanks in advance.










share|improve this question



























    0















    Good afternoon.



    I have required json, which contains the basic template for the layout of Adaptive Cards (bot framework).



    Here's this json:






    {
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0",
    "type": "AdaptiveCard",
    "speak": "",
    "body": [
    {
    "type": "TextBlock",
    "horizontalAlignment": "center",
    "text": "Все машины",
    "weight": "bolder",
    "isSubtle": false
    },
    {
    "type": "TextBlock",
    "text": "Внимание, вы вошли в режим тендера.",
    "separator": true
    }
    ],
    "actions": [
    {
    "type": "Action.Submit",
    "title": "Подтвердить лот(ы)",
    "data": {
    "msteams": {
    "type": "messageBack",
    "displayText": "Идет подтверждение ваших лотов, ожидайте!",
    "text": "/accept",
    "value": "{"x": "bfVal", "y": "from value"}"
    }
    }
    },
    {
    "type": "Action.Submit",
    "title": "Отменить все лоты",
    "data": {
    "x": "123",
    "msteams": {
    "type": "messageBack",
    "displayText": "Идет отменение ваших лотов, ожидайте!",
    "text": "/cancel",
    "value": "{"bfKey": "bfVal", "conflictKey": "from value"}"
    }
    }
    }
    ]
    }





    I also have a loop that takes data from my source and forms another json from it.






    try {
    // Pull in the data from Microsoft Graph.
    const client = new SimpleGraphClient(tokenResponse.token);
    const me = await client.getList();

    var i = 0;
    while (i < me['value'].length) {
    feed = {
    "type": "ColumnSet",
    "separator": true,
    "columns": [
    {
    "type": "Column",
    "width": 1,
    "items": [
    {
    "type": "TextBlock",
    "text": "Продукт",
    "isSubtle": true
    },
    {
    "type": "TextBlock",
    "size": "extraLarge",
    "color": "accent",
    "text": me.value[i].fields.Good,
    "spacing": "none"
    },
    {
    "type": "TextBlock",
    "text": "Дата: " + dateFormat(me.value[i].fields.ShipmentDateTime, 'dd-mm-yyyy'),
    "spacing": "yes"
    }
    ]
    },
    {
    "type": "Column",
    "width": "auto",
    "items": [
    {
    "type": "TextBlock",
    "text": " "
    },
    {
    "type": "Image",
    "url": "https://png.pngtree.com/svg/20170614/engine_oil_410031.png",
    "size": "medium",
    "spacing": "yes"
    },
    {
    "type": "TextBlock",
    "text": " ID: " + me.value[i].fields.id,
    "value": me.value[i].fields.id
    }
    ]
    },
    {
    "type": "Column",
    "width": 1,
    "items": [
    {
    "type": "TextBlock",
    "horizontalAlignment": "right",
    "text": "RUB",
    "isSubtle": true
    },
    {
    "type": "TextBlock",
    "horizontalAlignment": "right",
    "size": "extraLarge",
    "color": "accent",
    "text": me.value[i].fields.PricePerTon,
    "spacing": "none"
    },
    {
    "type": "Input.Toggle",
    "title": "Приобрести лот",
    "valueOn": "true",
    "valueOff": "false",
    "id": "buyGood",
    "spacing": "yes"
    }
    ]
    }
    ]
    }

    tender.body.push(feed);
    i++;

    }





    Then I combine these json.



    This works well, but when you retrieve the data again, the data is doubled.



    How can this be resolved?



    Thanks in advance.










    share|improve this question

























      0












      0








      0








      Good afternoon.



      I have required json, which contains the basic template for the layout of Adaptive Cards (bot framework).



      Here's this json:






      {
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "version": "1.0",
      "type": "AdaptiveCard",
      "speak": "",
      "body": [
      {
      "type": "TextBlock",
      "horizontalAlignment": "center",
      "text": "Все машины",
      "weight": "bolder",
      "isSubtle": false
      },
      {
      "type": "TextBlock",
      "text": "Внимание, вы вошли в режим тендера.",
      "separator": true
      }
      ],
      "actions": [
      {
      "type": "Action.Submit",
      "title": "Подтвердить лот(ы)",
      "data": {
      "msteams": {
      "type": "messageBack",
      "displayText": "Идет подтверждение ваших лотов, ожидайте!",
      "text": "/accept",
      "value": "{"x": "bfVal", "y": "from value"}"
      }
      }
      },
      {
      "type": "Action.Submit",
      "title": "Отменить все лоты",
      "data": {
      "x": "123",
      "msteams": {
      "type": "messageBack",
      "displayText": "Идет отменение ваших лотов, ожидайте!",
      "text": "/cancel",
      "value": "{"bfKey": "bfVal", "conflictKey": "from value"}"
      }
      }
      }
      ]
      }





      I also have a loop that takes data from my source and forms another json from it.






      try {
      // Pull in the data from Microsoft Graph.
      const client = new SimpleGraphClient(tokenResponse.token);
      const me = await client.getList();

      var i = 0;
      while (i < me['value'].length) {
      feed = {
      "type": "ColumnSet",
      "separator": true,
      "columns": [
      {
      "type": "Column",
      "width": 1,
      "items": [
      {
      "type": "TextBlock",
      "text": "Продукт",
      "isSubtle": true
      },
      {
      "type": "TextBlock",
      "size": "extraLarge",
      "color": "accent",
      "text": me.value[i].fields.Good,
      "spacing": "none"
      },
      {
      "type": "TextBlock",
      "text": "Дата: " + dateFormat(me.value[i].fields.ShipmentDateTime, 'dd-mm-yyyy'),
      "spacing": "yes"
      }
      ]
      },
      {
      "type": "Column",
      "width": "auto",
      "items": [
      {
      "type": "TextBlock",
      "text": " "
      },
      {
      "type": "Image",
      "url": "https://png.pngtree.com/svg/20170614/engine_oil_410031.png",
      "size": "medium",
      "spacing": "yes"
      },
      {
      "type": "TextBlock",
      "text": " ID: " + me.value[i].fields.id,
      "value": me.value[i].fields.id
      }
      ]
      },
      {
      "type": "Column",
      "width": 1,
      "items": [
      {
      "type": "TextBlock",
      "horizontalAlignment": "right",
      "text": "RUB",
      "isSubtle": true
      },
      {
      "type": "TextBlock",
      "horizontalAlignment": "right",
      "size": "extraLarge",
      "color": "accent",
      "text": me.value[i].fields.PricePerTon,
      "spacing": "none"
      },
      {
      "type": "Input.Toggle",
      "title": "Приобрести лот",
      "valueOn": "true",
      "valueOff": "false",
      "id": "buyGood",
      "spacing": "yes"
      }
      ]
      }
      ]
      }

      tender.body.push(feed);
      i++;

      }





      Then I combine these json.



      This works well, but when you retrieve the data again, the data is doubled.



      How can this be resolved?



      Thanks in advance.










      share|improve this question














      Good afternoon.



      I have required json, which contains the basic template for the layout of Adaptive Cards (bot framework).



      Here's this json:






      {
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "version": "1.0",
      "type": "AdaptiveCard",
      "speak": "",
      "body": [
      {
      "type": "TextBlock",
      "horizontalAlignment": "center",
      "text": "Все машины",
      "weight": "bolder",
      "isSubtle": false
      },
      {
      "type": "TextBlock",
      "text": "Внимание, вы вошли в режим тендера.",
      "separator": true
      }
      ],
      "actions": [
      {
      "type": "Action.Submit",
      "title": "Подтвердить лот(ы)",
      "data": {
      "msteams": {
      "type": "messageBack",
      "displayText": "Идет подтверждение ваших лотов, ожидайте!",
      "text": "/accept",
      "value": "{"x": "bfVal", "y": "from value"}"
      }
      }
      },
      {
      "type": "Action.Submit",
      "title": "Отменить все лоты",
      "data": {
      "x": "123",
      "msteams": {
      "type": "messageBack",
      "displayText": "Идет отменение ваших лотов, ожидайте!",
      "text": "/cancel",
      "value": "{"bfKey": "bfVal", "conflictKey": "from value"}"
      }
      }
      }
      ]
      }





      I also have a loop that takes data from my source and forms another json from it.






      try {
      // Pull in the data from Microsoft Graph.
      const client = new SimpleGraphClient(tokenResponse.token);
      const me = await client.getList();

      var i = 0;
      while (i < me['value'].length) {
      feed = {
      "type": "ColumnSet",
      "separator": true,
      "columns": [
      {
      "type": "Column",
      "width": 1,
      "items": [
      {
      "type": "TextBlock",
      "text": "Продукт",
      "isSubtle": true
      },
      {
      "type": "TextBlock",
      "size": "extraLarge",
      "color": "accent",
      "text": me.value[i].fields.Good,
      "spacing": "none"
      },
      {
      "type": "TextBlock",
      "text": "Дата: " + dateFormat(me.value[i].fields.ShipmentDateTime, 'dd-mm-yyyy'),
      "spacing": "yes"
      }
      ]
      },
      {
      "type": "Column",
      "width": "auto",
      "items": [
      {
      "type": "TextBlock",
      "text": " "
      },
      {
      "type": "Image",
      "url": "https://png.pngtree.com/svg/20170614/engine_oil_410031.png",
      "size": "medium",
      "spacing": "yes"
      },
      {
      "type": "TextBlock",
      "text": " ID: " + me.value[i].fields.id,
      "value": me.value[i].fields.id
      }
      ]
      },
      {
      "type": "Column",
      "width": 1,
      "items": [
      {
      "type": "TextBlock",
      "horizontalAlignment": "right",
      "text": "RUB",
      "isSubtle": true
      },
      {
      "type": "TextBlock",
      "horizontalAlignment": "right",
      "size": "extraLarge",
      "color": "accent",
      "text": me.value[i].fields.PricePerTon,
      "spacing": "none"
      },
      {
      "type": "Input.Toggle",
      "title": "Приобрести лот",
      "valueOn": "true",
      "valueOff": "false",
      "id": "buyGood",
      "spacing": "yes"
      }
      ]
      }
      ]
      }

      tender.body.push(feed);
      i++;

      }





      Then I combine these json.



      This works well, but when you retrieve the data again, the data is doubled.



      How can this be resolved?



      Thanks in advance.






      {
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "version": "1.0",
      "type": "AdaptiveCard",
      "speak": "",
      "body": [
      {
      "type": "TextBlock",
      "horizontalAlignment": "center",
      "text": "Все машины",
      "weight": "bolder",
      "isSubtle": false
      },
      {
      "type": "TextBlock",
      "text": "Внимание, вы вошли в режим тендера.",
      "separator": true
      }
      ],
      "actions": [
      {
      "type": "Action.Submit",
      "title": "Подтвердить лот(ы)",
      "data": {
      "msteams": {
      "type": "messageBack",
      "displayText": "Идет подтверждение ваших лотов, ожидайте!",
      "text": "/accept",
      "value": "{"x": "bfVal", "y": "from value"}"
      }
      }
      },
      {
      "type": "Action.Submit",
      "title": "Отменить все лоты",
      "data": {
      "x": "123",
      "msteams": {
      "type": "messageBack",
      "displayText": "Идет отменение ваших лотов, ожидайте!",
      "text": "/cancel",
      "value": "{"bfKey": "bfVal", "conflictKey": "from value"}"
      }
      }
      }
      ]
      }





      {
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "version": "1.0",
      "type": "AdaptiveCard",
      "speak": "",
      "body": [
      {
      "type": "TextBlock",
      "horizontalAlignment": "center",
      "text": "Все машины",
      "weight": "bolder",
      "isSubtle": false
      },
      {
      "type": "TextBlock",
      "text": "Внимание, вы вошли в режим тендера.",
      "separator": true
      }
      ],
      "actions": [
      {
      "type": "Action.Submit",
      "title": "Подтвердить лот(ы)",
      "data": {
      "msteams": {
      "type": "messageBack",
      "displayText": "Идет подтверждение ваших лотов, ожидайте!",
      "text": "/accept",
      "value": "{"x": "bfVal", "y": "from value"}"
      }
      }
      },
      {
      "type": "Action.Submit",
      "title": "Отменить все лоты",
      "data": {
      "x": "123",
      "msteams": {
      "type": "messageBack",
      "displayText": "Идет отменение ваших лотов, ожидайте!",
      "text": "/cancel",
      "value": "{"bfKey": "bfVal", "conflictKey": "from value"}"
      }
      }
      }
      ]
      }





      try {
      // Pull in the data from Microsoft Graph.
      const client = new SimpleGraphClient(tokenResponse.token);
      const me = await client.getList();

      var i = 0;
      while (i < me['value'].length) {
      feed = {
      "type": "ColumnSet",
      "separator": true,
      "columns": [
      {
      "type": "Column",
      "width": 1,
      "items": [
      {
      "type": "TextBlock",
      "text": "Продукт",
      "isSubtle": true
      },
      {
      "type": "TextBlock",
      "size": "extraLarge",
      "color": "accent",
      "text": me.value[i].fields.Good,
      "spacing": "none"
      },
      {
      "type": "TextBlock",
      "text": "Дата: " + dateFormat(me.value[i].fields.ShipmentDateTime, 'dd-mm-yyyy'),
      "spacing": "yes"
      }
      ]
      },
      {
      "type": "Column",
      "width": "auto",
      "items": [
      {
      "type": "TextBlock",
      "text": " "
      },
      {
      "type": "Image",
      "url": "https://png.pngtree.com/svg/20170614/engine_oil_410031.png",
      "size": "medium",
      "spacing": "yes"
      },
      {
      "type": "TextBlock",
      "text": " ID: " + me.value[i].fields.id,
      "value": me.value[i].fields.id
      }
      ]
      },
      {
      "type": "Column",
      "width": 1,
      "items": [
      {
      "type": "TextBlock",
      "horizontalAlignment": "right",
      "text": "RUB",
      "isSubtle": true
      },
      {
      "type": "TextBlock",
      "horizontalAlignment": "right",
      "size": "extraLarge",
      "color": "accent",
      "text": me.value[i].fields.PricePerTon,
      "spacing": "none"
      },
      {
      "type": "Input.Toggle",
      "title": "Приобрести лот",
      "valueOn": "true",
      "valueOff": "false",
      "id": "buyGood",
      "spacing": "yes"
      }
      ]
      }
      ]
      }

      tender.body.push(feed);
      i++;

      }





      try {
      // Pull in the data from Microsoft Graph.
      const client = new SimpleGraphClient(tokenResponse.token);
      const me = await client.getList();

      var i = 0;
      while (i < me['value'].length) {
      feed = {
      "type": "ColumnSet",
      "separator": true,
      "columns": [
      {
      "type": "Column",
      "width": 1,
      "items": [
      {
      "type": "TextBlock",
      "text": "Продукт",
      "isSubtle": true
      },
      {
      "type": "TextBlock",
      "size": "extraLarge",
      "color": "accent",
      "text": me.value[i].fields.Good,
      "spacing": "none"
      },
      {
      "type": "TextBlock",
      "text": "Дата: " + dateFormat(me.value[i].fields.ShipmentDateTime, 'dd-mm-yyyy'),
      "spacing": "yes"
      }
      ]
      },
      {
      "type": "Column",
      "width": "auto",
      "items": [
      {
      "type": "TextBlock",
      "text": " "
      },
      {
      "type": "Image",
      "url": "https://png.pngtree.com/svg/20170614/engine_oil_410031.png",
      "size": "medium",
      "spacing": "yes"
      },
      {
      "type": "TextBlock",
      "text": " ID: " + me.value[i].fields.id,
      "value": me.value[i].fields.id
      }
      ]
      },
      {
      "type": "Column",
      "width": 1,
      "items": [
      {
      "type": "TextBlock",
      "horizontalAlignment": "right",
      "text": "RUB",
      "isSubtle": true
      },
      {
      "type": "TextBlock",
      "horizontalAlignment": "right",
      "size": "extraLarge",
      "color": "accent",
      "text": me.value[i].fields.PricePerTon,
      "spacing": "none"
      },
      {
      "type": "Input.Toggle",
      "title": "Приобрести лот",
      "valueOn": "true",
      "valueOff": "false",
      "id": "buyGood",
      "spacing": "yes"
      }
      ]
      }
      ]
      }

      tender.body.push(feed);
      i++;

      }






      javascript node.js botframework






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 28 '18 at 5:16









      Danil KalininDanil Kalinin

      276




      276
























          1 Answer
          1






          active

          oldest

          votes


















          0














          It looks like every time you create a new card, you are appending the JSON object you created in the while loop to your required JSON object. Consequently, the next time you try to create a new card, the data from the previous request is still stored in your required JSON object. To avoid this, create a copy of the required JSON Object and store it in a different variable before your while loop. You can use JSON.parse(JSON.stringify(obj)) to create a copy of a JSON Object.



          Your code should look something like this:



          // create a copy of the required JSON Object
          // and store it in a new variable
          const card = JSON.parse(JSON.stringify(tender));

          var i = 0;
          while (i < me['value'].length) {
          let feed = {
          "type": "ColumnSet",
          "separator": true,
          ...
          }

          // push feed to `card` instead of `tender`
          card.body.push(feed);
          i++;
          }

          ...

          // send `card` to user instead of `tender`
          await turnContext.sendActivity({
          text: "Double Data Card",
          attachments: [CardFactory.adaptiveCard(card)]
          });





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53512584%2fwhy-data-is-doubled-how-i-can-fix-it%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It looks like every time you create a new card, you are appending the JSON object you created in the while loop to your required JSON object. Consequently, the next time you try to create a new card, the data from the previous request is still stored in your required JSON object. To avoid this, create a copy of the required JSON Object and store it in a different variable before your while loop. You can use JSON.parse(JSON.stringify(obj)) to create a copy of a JSON Object.



            Your code should look something like this:



            // create a copy of the required JSON Object
            // and store it in a new variable
            const card = JSON.parse(JSON.stringify(tender));

            var i = 0;
            while (i < me['value'].length) {
            let feed = {
            "type": "ColumnSet",
            "separator": true,
            ...
            }

            // push feed to `card` instead of `tender`
            card.body.push(feed);
            i++;
            }

            ...

            // send `card` to user instead of `tender`
            await turnContext.sendActivity({
            text: "Double Data Card",
            attachments: [CardFactory.adaptiveCard(card)]
            });





            share|improve this answer




























              0














              It looks like every time you create a new card, you are appending the JSON object you created in the while loop to your required JSON object. Consequently, the next time you try to create a new card, the data from the previous request is still stored in your required JSON object. To avoid this, create a copy of the required JSON Object and store it in a different variable before your while loop. You can use JSON.parse(JSON.stringify(obj)) to create a copy of a JSON Object.



              Your code should look something like this:



              // create a copy of the required JSON Object
              // and store it in a new variable
              const card = JSON.parse(JSON.stringify(tender));

              var i = 0;
              while (i < me['value'].length) {
              let feed = {
              "type": "ColumnSet",
              "separator": true,
              ...
              }

              // push feed to `card` instead of `tender`
              card.body.push(feed);
              i++;
              }

              ...

              // send `card` to user instead of `tender`
              await turnContext.sendActivity({
              text: "Double Data Card",
              attachments: [CardFactory.adaptiveCard(card)]
              });





              share|improve this answer


























                0












                0








                0







                It looks like every time you create a new card, you are appending the JSON object you created in the while loop to your required JSON object. Consequently, the next time you try to create a new card, the data from the previous request is still stored in your required JSON object. To avoid this, create a copy of the required JSON Object and store it in a different variable before your while loop. You can use JSON.parse(JSON.stringify(obj)) to create a copy of a JSON Object.



                Your code should look something like this:



                // create a copy of the required JSON Object
                // and store it in a new variable
                const card = JSON.parse(JSON.stringify(tender));

                var i = 0;
                while (i < me['value'].length) {
                let feed = {
                "type": "ColumnSet",
                "separator": true,
                ...
                }

                // push feed to `card` instead of `tender`
                card.body.push(feed);
                i++;
                }

                ...

                // send `card` to user instead of `tender`
                await turnContext.sendActivity({
                text: "Double Data Card",
                attachments: [CardFactory.adaptiveCard(card)]
                });





                share|improve this answer













                It looks like every time you create a new card, you are appending the JSON object you created in the while loop to your required JSON object. Consequently, the next time you try to create a new card, the data from the previous request is still stored in your required JSON object. To avoid this, create a copy of the required JSON Object and store it in a different variable before your while loop. You can use JSON.parse(JSON.stringify(obj)) to create a copy of a JSON Object.



                Your code should look something like this:



                // create a copy of the required JSON Object
                // and store it in a new variable
                const card = JSON.parse(JSON.stringify(tender));

                var i = 0;
                while (i < me['value'].length) {
                let feed = {
                "type": "ColumnSet",
                "separator": true,
                ...
                }

                // push feed to `card` instead of `tender`
                card.body.push(feed);
                i++;
                }

                ...

                // send `card` to user instead of `tender`
                await turnContext.sendActivity({
                text: "Double Data Card",
                attachments: [CardFactory.adaptiveCard(card)]
                });






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 28 '18 at 20:39









                tdurnfordtdurnford

                7628




                7628
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53512584%2fwhy-data-is-doubled-how-i-can-fix-it%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)