TypeError: Cannot call method "toLowerCase" of undefined

116 views
Skip to first unread message

Theo Kinderknecht

unread,
Feb 7, 2021, 7:44:23 AM2/7/21
to Google Ads Scripts Forum

Hallo,

i try to work with Script for Google Shopping and get this error:

TypeError: Cannot call method "toLowerCase" of undefined. (file Code.gs, line 57)

This is the Line:

 }
    var keyword = spreadsheetData[i][2];
    keyword = keyword.toLowerCase().replace(/[^\w\s\d&]/g,' ').replace(/ +/g, ' ').trim();
    keywords[campaignName][adGroupName].push(keyword);
    numberOfKeywords++;
    var keywordWords = keyword.split(' ');
    for (var k = 0; k < keywordWords.length; k++) {
      if (keywordWords[k].length > 4) {
        words[campaignName][adGroupName][keywordWords[k]] = true;
      }

Thank you for Help!

Google Ads Scripts Forum Advisor

unread,
Feb 7, 2021, 10:25:31 PM2/7/21
to adwords...@googlegroups.com

Hi Theo,

 

Thanks for reaching out. I am Harry, from the Google Ads Scripts Team and allow me to assist you in this. I would assume that the undefined error is caused by the spreadsheetData[i][2] variable not having or containing any value; thus, the toLowerCase method would not be able to proceed. Kindly try to debug this code block and check if it is correctly retrieving the values from your spreadsheet. You may simply add a logger statement "Logger.log(keyword)" after your keyword variable to check its value. Please see Logger output for more information.

 

If you would need further assistance, kindly provide the script name and your CID and also a shareable link or a copy of the spreadsheet file so that I could check this on our end. You may send them here or privately via the reply to author option. If this option is not available at your end, you may send the requested information through our email (googleadsscr...@google.com) instead.

 

Thanks,

Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2BebBA:ref
Reply all
Reply to author
Forward
0 new messages