Error when gmail create label from an array












0















I'm trying to create gmail labels from a list in a connected spreadsheet. I have connected to the spreadsheet and had no issues pulling in the the array. However in the for loop, I'm getting an error of Invalid Argument for this line of code:



var Label = GmailApp.createLabel(selection[i]);.



I am creating this script in google app script and have already enabled the api for gmail and google sheets. The createLabel function works fine with the array if I input an actual number but it won't seem to read my variable from the for loop. Can you help me figure out the issue?



Below is the rest of my code:



function myFunction() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var selection = sheet.getRange("A1:A13").getValues();

var arrayLength = selection.length;



Logger.log(arrayLength);


//For each value in the array, create a gmail label for it



for (var i=0; i <arrayLength; i++) {


var Label = GmailApp.createLabel(selection[i]);

Logger.log(Label + "has been created");


}

}









share|improve this question

























  • Selection is a 2D array, try selection[i][0]

    – TheWizEd
    Nov 23 '18 at 17:24











  • I updated the line of code to show the below but its still giving me an error. var Label = GmailApp.createLabel(selection[i][0]);

    – Alexis McPhatter
    Nov 23 '18 at 17:48













  • I copied your code as is and didn't get any error. Have you checked the value of section?

    – Mr.Rebot
    Nov 26 '18 at 22:52











  • Did you mean the value of selection? yes, I checked that. But if you meant the value of section as you wrote it, I'm not sure what you mean by that. I kept getting the invalid argument error on this code. Since this matter was time sensitive I ended up taking out the 2d array completely and went with a work around, but I still want to know if there was a way for me to get this working. One of the weird things that I notices with my original code, it worked initially when I tested it but when I came back to the code the next day it started showing an error. No one else edited it.

    – Alexis McPhatter
    Nov 28 '18 at 13:15


















0















I'm trying to create gmail labels from a list in a connected spreadsheet. I have connected to the spreadsheet and had no issues pulling in the the array. However in the for loop, I'm getting an error of Invalid Argument for this line of code:



var Label = GmailApp.createLabel(selection[i]);.



I am creating this script in google app script and have already enabled the api for gmail and google sheets. The createLabel function works fine with the array if I input an actual number but it won't seem to read my variable from the for loop. Can you help me figure out the issue?



Below is the rest of my code:



function myFunction() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var selection = sheet.getRange("A1:A13").getValues();

var arrayLength = selection.length;



Logger.log(arrayLength);


//For each value in the array, create a gmail label for it



for (var i=0; i <arrayLength; i++) {


var Label = GmailApp.createLabel(selection[i]);

Logger.log(Label + "has been created");


}

}









share|improve this question

























  • Selection is a 2D array, try selection[i][0]

    – TheWizEd
    Nov 23 '18 at 17:24











  • I updated the line of code to show the below but its still giving me an error. var Label = GmailApp.createLabel(selection[i][0]);

    – Alexis McPhatter
    Nov 23 '18 at 17:48













  • I copied your code as is and didn't get any error. Have you checked the value of section?

    – Mr.Rebot
    Nov 26 '18 at 22:52











  • Did you mean the value of selection? yes, I checked that. But if you meant the value of section as you wrote it, I'm not sure what you mean by that. I kept getting the invalid argument error on this code. Since this matter was time sensitive I ended up taking out the 2d array completely and went with a work around, but I still want to know if there was a way for me to get this working. One of the weird things that I notices with my original code, it worked initially when I tested it but when I came back to the code the next day it started showing an error. No one else edited it.

    – Alexis McPhatter
    Nov 28 '18 at 13:15
















0












0








0








I'm trying to create gmail labels from a list in a connected spreadsheet. I have connected to the spreadsheet and had no issues pulling in the the array. However in the for loop, I'm getting an error of Invalid Argument for this line of code:



var Label = GmailApp.createLabel(selection[i]);.



I am creating this script in google app script and have already enabled the api for gmail and google sheets. The createLabel function works fine with the array if I input an actual number but it won't seem to read my variable from the for loop. Can you help me figure out the issue?



Below is the rest of my code:



function myFunction() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var selection = sheet.getRange("A1:A13").getValues();

var arrayLength = selection.length;



Logger.log(arrayLength);


//For each value in the array, create a gmail label for it



for (var i=0; i <arrayLength; i++) {


var Label = GmailApp.createLabel(selection[i]);

Logger.log(Label + "has been created");


}

}









share|improve this question
















I'm trying to create gmail labels from a list in a connected spreadsheet. I have connected to the spreadsheet and had no issues pulling in the the array. However in the for loop, I'm getting an error of Invalid Argument for this line of code:



var Label = GmailApp.createLabel(selection[i]);.



I am creating this script in google app script and have already enabled the api for gmail and google sheets. The createLabel function works fine with the array if I input an actual number but it won't seem to read my variable from the for loop. Can you help me figure out the issue?



Below is the rest of my code:



function myFunction() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var selection = sheet.getRange("A1:A13").getValues();

var arrayLength = selection.length;



Logger.log(arrayLength);


//For each value in the array, create a gmail label for it



for (var i=0; i <arrayLength; i++) {


var Label = GmailApp.createLabel(selection[i]);

Logger.log(Label + "has been created");


}

}






arrays google-apps-script gmail-api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 16:14









fewlinesofcode

2,0671818




2,0671818










asked Nov 23 '18 at 15:15









Alexis McPhatterAlexis McPhatter

11




11













  • Selection is a 2D array, try selection[i][0]

    – TheWizEd
    Nov 23 '18 at 17:24











  • I updated the line of code to show the below but its still giving me an error. var Label = GmailApp.createLabel(selection[i][0]);

    – Alexis McPhatter
    Nov 23 '18 at 17:48













  • I copied your code as is and didn't get any error. Have you checked the value of section?

    – Mr.Rebot
    Nov 26 '18 at 22:52











  • Did you mean the value of selection? yes, I checked that. But if you meant the value of section as you wrote it, I'm not sure what you mean by that. I kept getting the invalid argument error on this code. Since this matter was time sensitive I ended up taking out the 2d array completely and went with a work around, but I still want to know if there was a way for me to get this working. One of the weird things that I notices with my original code, it worked initially when I tested it but when I came back to the code the next day it started showing an error. No one else edited it.

    – Alexis McPhatter
    Nov 28 '18 at 13:15





















  • Selection is a 2D array, try selection[i][0]

    – TheWizEd
    Nov 23 '18 at 17:24











  • I updated the line of code to show the below but its still giving me an error. var Label = GmailApp.createLabel(selection[i][0]);

    – Alexis McPhatter
    Nov 23 '18 at 17:48













  • I copied your code as is and didn't get any error. Have you checked the value of section?

    – Mr.Rebot
    Nov 26 '18 at 22:52











  • Did you mean the value of selection? yes, I checked that. But if you meant the value of section as you wrote it, I'm not sure what you mean by that. I kept getting the invalid argument error on this code. Since this matter was time sensitive I ended up taking out the 2d array completely and went with a work around, but I still want to know if there was a way for me to get this working. One of the weird things that I notices with my original code, it worked initially when I tested it but when I came back to the code the next day it started showing an error. No one else edited it.

    – Alexis McPhatter
    Nov 28 '18 at 13:15



















Selection is a 2D array, try selection[i][0]

– TheWizEd
Nov 23 '18 at 17:24





Selection is a 2D array, try selection[i][0]

– TheWizEd
Nov 23 '18 at 17:24













I updated the line of code to show the below but its still giving me an error. var Label = GmailApp.createLabel(selection[i][0]);

– Alexis McPhatter
Nov 23 '18 at 17:48







I updated the line of code to show the below but its still giving me an error. var Label = GmailApp.createLabel(selection[i][0]);

– Alexis McPhatter
Nov 23 '18 at 17:48















I copied your code as is and didn't get any error. Have you checked the value of section?

– Mr.Rebot
Nov 26 '18 at 22:52





I copied your code as is and didn't get any error. Have you checked the value of section?

– Mr.Rebot
Nov 26 '18 at 22:52













Did you mean the value of selection? yes, I checked that. But if you meant the value of section as you wrote it, I'm not sure what you mean by that. I kept getting the invalid argument error on this code. Since this matter was time sensitive I ended up taking out the 2d array completely and went with a work around, but I still want to know if there was a way for me to get this working. One of the weird things that I notices with my original code, it worked initially when I tested it but when I came back to the code the next day it started showing an error. No one else edited it.

– Alexis McPhatter
Nov 28 '18 at 13:15







Did you mean the value of selection? yes, I checked that. But if you meant the value of section as you wrote it, I'm not sure what you mean by that. I kept getting the invalid argument error on this code. Since this matter was time sensitive I ended up taking out the 2d array completely and went with a work around, but I still want to know if there was a way for me to get this working. One of the weird things that I notices with my original code, it worked initially when I tested it but when I came back to the code the next day it started showing an error. No one else edited it.

– Alexis McPhatter
Nov 28 '18 at 13:15














0






active

oldest

votes











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%2f53449146%2ferror-when-gmail-create-label-from-an-array%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53449146%2ferror-when-gmail-create-label-from-an-array%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

Feedback on college project

Futebolista

Albești (Vaslui)