Erik J
Erik J

Reputation: 57

Logger.log shows all of the nested array values, but the sheet only gets the first item added

The API I am accessing has an array (tickets), that contains a nested array of strings (tags). When I loop through to get to the nested array values, I am able to see the full list of tags (in the red box of the screenshot below).

enter image description here

When I view the sheet, however, it is only returning the first item of the array as you can see in the below screenshot.

enter image description here

I am sure this is something silly, but I cannot figure it out. My code is below. Thank you for any help you can provide.

var example = []
 results.forEach(function(tickets){
  var temp = [];
   tickets.tags.forEach(function(tags){
      temp.push(tags);
   })
   example.push([tickets["resolution_time"],tickets["created_at"], tickets["priority"], tickets["state"],tickets["id"], tickets["closed_by"], temp])
 })

Logger.log(example + "is this working?");

var len = example.length;

//clear existing data
sheet.getRange(2,1,2000,8).clearContent();

//paste in the values
sheet.getRange(sheet.getLastRow() +1,1,len,7).setValues(example);

Upvotes: 1

Views: 87

Answers (1)

mbojko
mbojko

Reputation: 14679

I see you trying to put an array of strings (temp) into a single cell of the sheet. Can you even do that?

Replace

  var temp = [];
   tickets.tags.forEach(function(tags){
      temp.push(tags);
   })

with

  var temp = tickets.tags.join(',')

Upvotes: 2

Related Questions