TypeError: Cannot read properties of undefined (reading 'length')

1,213 views
Skip to first unread message

Victor NC

unread,
Mar 20, 2024, 9:12:46 AM3/20/24
to Google Ads Scripts Forum
Looks Length, replace are all error@@
Can someone advise?
Thank you!

var sheetLineNotifyTokens = SpreadsheetApp.getActive().getSheetByName("Line Notify Tokens");
var sheetLineNotifyTokenslastRow = sheetLineNotifyTokens.getLastRow();
var sheetLineNotifyTokenslastColumn = sheetLineNotifyTokens.getLastColumn();
var sheetConfig = SpreadsheetApp.getActive().getSheetByName("Setting");
var sheetConfigData = sheetConfig.getRange(1, 2, sheetConfig.getLastRow(), sheetConfig.getLastColumn() - 1).getValues();
var serviceName = sheetConfigData[0][0].replace(/\r?\n|\r/g,"");
var callBackURL = sheetConfigData[3][0].replace(/\r?\n|\r/g,"");
var clientID = sheetConfigData[4][0].replace(/\r?\n|\r/g,"");
var clientSecret = sheetConfigData[5][0].replace(/\r?\n|\r/g,"");
var welcomeMessage= sheetConfigData[6][0];
var startImages = transformArray(sheetConfigData[7]);
var finishImages = transformArray(sheetConfigData[8]);

// Line Notify Tokens
var tokenTargetTypeColumn = 1;
var tokenTargetColumn = 2;
var tokenDisconnectColumn = 4;
var tokenDeleteColumn = 6;

//Delete blank
function transformArray(arrayData) {
var returnArray = [];
for (var i = 0; i < arrayData.length; i++) {
if (arrayData[i] !== "") {returnArray.push(arrayData[i].replace(/\r?\n|\r/g,""));}
}
return returnArray;
}

Google Ads Scripts Forum Advisor

unread,
Mar 20, 2024, 1:30:52 PM3/20/24
to adwords...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads Scripts support team.

Kindly note that the error message "TypeError: Cannot read properties of undefined (reading 'length')" in your Google Ads Script indicates that your script is trying to access a property of a variable that doesn't have any values assigned to it. This is usually caused by an undefined variable or an error in retrieving data from Google Ads or a spreadsheet.

If the issue still persists, kindly provide us with the following details:
  • Google Ads account ID / CID
  • Name of the affected script
  • Error details or the screenshot of the issue (if any)
  • If the script uses a spreadsheet, please provide a shareable link to the spreadsheet.
You can share the requested details via Reply privately to the author option or a direct private reply to this email.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02s05uh:ref" (ADR-00228030)

Thanks,
 
Google Logo Google Ads Scripts Team



 

Nils Rooijmans

unread,
Apr 11, 2024, 3:22:46 AM4/11/24
to Google Ads Scripts Forum
based on the code you shared it looks like there's data missing in your  Google Sheet: rox 7 or 8 in sheet  "Setting"

Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/

Shannon Olsen

unread,
Apr 11, 2024, 11:12:50 PM4/11/24
to Nils Rooijmans via Google Ads Scripts Forum
Thanks Nils,

This is very helpful! Moving forward, do you mind if I contact you directly with script questions?

Thanks,
Shannon 



--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/49ae0a4f-3942-4770-bbeb-6a7ca73e8f88n%40googlegroups.com.

Nils Rooijmans

unread,
Apr 12, 2024, 5:55:22 AM4/12/24
to Google Ads Scripts Forum
glad I could be of help, and feel free to reach out to me directly. you know where to find me :)

Google Ads Scripts Forum Advisor

unread,
Apr 12, 2024, 1:44:05 PM4/12/24
to adwords...@googlegroups.com

Hi,

Thanks @Nils for providing a solution. Shannon Please reach out to us if you have any queries related to the Google Ads Scripts.

Reply all
Reply to author
Forward
0 new messages