Cannot set property of undefined

205 views
Skip to first unread message

Michal Marek

unread,
May 26, 2022, 5:53:19 AM5/26/22
to Google Apps Script Community
Hi, I'd like to ask for help.
The following code works in 4 other cases, but not now.
Returns this error:
TypeError: Cannot set property 'vendorid' of undefined
email @ Code.gs: 35
Wouldn't you know what could be wrong? Thanks.

function email() {


var ss = SpreadsheetApp.getActiveSpreadsheet()

var tab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('List 1')
var column = tab.getRange('A' + tab.getMaxRows())
var last = column.getNextDataCell(SpreadsheetApp.Direction.UP).getA1Notation().slice(1)
var email = tab.getRange(last,5).getValue();
var odesilatel = tab.getRange(last,2).getValue();
var id = tab.getRange(last,6).getValue();
var pozadavek = tab.getRange(last,8).getValue();
var detail = tab.getRange(last,9).getValue();
var subject = "Potvrzení požadavku";
var zaslal = tab.getRange(last,11).getValue()
var emailcc = tab.getRange(last,12).getValue();
var check = tab.getRange(last,13).getValue()
if(check == "poslan")
{
}
else
{
if(zaslal == "DJ")
{

var templ = HtmlService.createTemplateFromFile('emaildj')

}
if(zaslal == "Partner")
{

var templ = HtmlService.createTemplateFromFile('emailpar')

}
templ.vendorid = id
templ.pozadavek = pozadavek
templ.detail = detail
var message = templ.evaluate().getContent();
MailApp.sendEmail({
      to: email,
      cc: emailcc,
      subject: subject,
      htmlBody: message,
      name: odesilatel
      });
            if(1 == 1){ss.getActiveSheet().getRange(last,13).setValue("poslan");}
}
}

Bruce Mcpherson

unread,
May 26, 2022, 6:00:19 AM5/26/22
to google-apps-sc...@googlegroups.com
if zaslal is neither "Partner" nor "DJ", templ will be undefined.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0e00b351-b187-4e2e-b5a9-8b8454f7d2c5n%40googlegroups.com.

Michal Marek

unread,
May 26, 2022, 6:10:46 AM5/26/22
to Google Apps Script Community
Thank you,
The error is not in the code, but in the source table.
I knew it was some crap, but I needed to push me the right direction.

Dne čtvrtek 26. května 2022 v 12:00:19 UTC+2 uživatel Bruce Mcpherson napsal:

Витя Коледа

unread,
Jun 20, 2022, 8:33:35 AM6/20/22
to google-apps-sc...@googlegroups.com

чт, 26 мая 2022 г., 13:10 Michal Marek <michal...@damejidlo.cz>:
Reply all
Reply to author
Forward
0 new messages