Time Off Request System error message

46 views
Skip to first unread message

Kayla Skillin

unread,
Jul 10, 2023, 3:10:36 PM7/10/23
to Google Apps Script Community
Hello,

I have been working on a project using the public article for the Apps Script Enhancement, and referencing the GitHub page but still coming up with errors when I run the script. 

I am admittedly a very novice user of Apps Script and coding but any help would be greatly appreciated. The error in the execution log that I have been getting consistently is below: 

Error
TypeError: Cannot read properties of undefined (reading 'match')
Code.gs:287
Code.gs:316
Code.gs:314
Code.gs:434


Thank you,
Kayla

💼

unread,
Jul 10, 2023, 3:19:06 PM7/10/23
to google-apps-sc...@googlegroups.com
Without seeing the script it’s difficult to provide feedback to your question. Based on the provided error whatever string you’re trying to .match() is undefined… missing … can’t be found. You need to debug your script from that point going up in the stack to find the reason why that string can’t be found.

On Jul 10, 2023, at 12:10 PM, Kayla Skillin <kayla....@gmail.com> wrote:

Hello,
--
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/9af0e0e1-8d9c-4192-ada1-a1cd7a8ef83fn%40googlegroups.com.

cbmserv...@gmail.com

unread,
Jul 10, 2023, 3:30:22 PM7/10/23
to google-apps-sc...@googlegroups.com

Hi Kayla,

 

It is probably failing because it did not read the values from the spreadsheet.

 

In the GitHub page, there is a list of things to do to prepare this to work for you. One thing mentioned is:

 

5. In your copy of the spreadsheet, capture the Spreadsheet Key.
This is the part of the URL between the two slashes following the “d,” highlighted here: https://docs.google.com/spreadsheets/d/…./

Did you make that change in your copy of the code?

--

Kayla Skillin

unread,
Jul 10, 2023, 3:50:58 PM7/10/23
to Google Apps Script Community
Hi George-

Thanks for the response - yes, I did change the Spreadsheet Key - still no luck. 

This may not be relevant, but any chance the problem could be in the deployment calling up outdated APIs? I have checked anything I could think of and it seems like the "send email as you" is a legacy API... 

Please pardon my ignorance!
Project OAuth Scopes
4 Scopes Requested

Send email as you

https://www.googleapis.com/auth/script.send_mail

See, edit, create, and delete all your Google Sheets spreadsheets

https://www.googleapis.com/auth/spreadsheets

See your primary Google Account email address

https://www.googleapis.com/auth/userinfo.email

See, edit, share, and permanently delete all the calendars you can access using Google Calendar

https://www.googleapis.com/auth/calendar

cbmserv...@gmail.com

unread,
Jul 10, 2023, 4:20:47 PM7/10/23
to google-apps-sc...@googlegroups.com

Looking at what is posted in Github, the MailApp.sendEmail that is used is still supported and has not been deprecated and have not heard of any plans to do so. So that is not the problem.

 

The line of code that is failing is this one (unless you add or removed some lines of code):

 

    manager_email = d[SETTINGS.MANAGERS_EMAIL_COLUMN_NAME].match(EMAIL_REGEX);

 

So it is trying to grab the manager’s email from the spreadsheet. But for some reason the value is undefined (meaning it was not able to read the data from the spreadsheet.

 

Was there something submitted for Manager’s email in the form data?

Kayla Skillin

unread,
Jul 11, 2023, 3:13:15 PM7/11/23
to google-apps-sc...@googlegroups.com
Thank you so much! I think I figured it out by changing the way the email address is actually written on the form. At least the form works functionally the way I want it to - cosmetically there are some things I would like to change. 

I would like to execute the script as an admin email in my domain so that the notifications emails do not come from me - is that possible?

You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/MTmhGG9eBtE/unsubscribe.
To unsubscribe from this group and all its topics, 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/007901d9b36b%24ff268f50%24fd73adf0%24%40gmail.com.

cbmserv...@gmail.com

unread,
Jul 11, 2023, 7:25:38 PM7/11/23
to google-apps-sc...@googlegroups.com

Yes, to do that, just delete the triggers you created, archive the deployment of the webapp.

 

Then give edit  access of spreadsheet to admin account, from admin account, re-create the trigger, and redo the deployment of the webapp. You will have to update the webapp url in the script to the new one.

Kayla Skillin

unread,
Jul 14, 2023, 10:54:20 AM7/14/23
to google-apps-sc...@googlegroups.com
That worked! Thank you! 

Unfortunately, it seems like everytime I get one thing fixed, another thing isn't working. Now getting an error code when the manager tries to approve or deny the request: "Invalid email: undefined (line 381, file "Code")"

Thinking it has something to do with this section of the code:
var approveByKey = function(k, user) {
var d = _getDataByKey(k);
d.state = APPROVED_STATE;
d.actor = user;
var message = Utils.processTemplate(SETTINGS.USER_APPROVAL_EMAIL, d);
var subject = Utils.processTemplate(SETTINGS.USER_APPROVAL_EMAIL_SUBJECT, d);
MailApp.sendEmail(d.email,subject,"",{ htmlBody: message });
if(SETTINGS.SEND_APPROVAL_NOTICE_EMAIL == 1) {
var message = Utils.processTemplate(SETTINGS.APPROVAL_NOTICE_EMAIL, d);
var subject = Utils.processTemplate(SETTINGS.APPROVAL_NOTICE_EMAIL_SUBJECT, d);
MailApp.sendEmail(SETTINGS.APPROVAL_NOTICE_EMAIL_TO, subject, "",{ htmlBody: message });
}
Logger.log(SETTINGS);
if (SETTINGS.CREATE_CALENDAR_EVENT == 1) {
Logger.log("Creating Calendar Event");
_createCalendarEventForDataRow(d);
}
setRowData(_sheet, d);
}



CBMServices Web

unread,
Jul 14, 2023, 2:41:10 PM7/14/23
to google-apps-sc...@googlegroups.com
Invalid email means whatever is being used as email address is incorrectly formatted. Email address can be concatenated with a comma separator.

I can't tell what line that is, you have multiple MailApp.sendEmail statements in that function, so check what is being used as email address (its the first argument passed to the sendEmail method and then put a Logger.log(emailaddress) statement above the MailApp.sendEmail so you can see in the logs what is being used as the email address. That should show you what is being used so you can correct it.

Jose armando Jara Osores

unread,
Jul 14, 2023, 3:08:54 PM7/14/23
to google-apps-sc...@googlegroups.com
The error you are experiencing is a TypeError indicating that you cannot read the properties of undefined in the 'match()' method. The error occurs at line 287 of your Code.gs file.

This usually means that you are trying to access a property of an object that is undefined or null. In this case, it appears that the object you are trying to use the 'match()' method on is not defined correctly.

To fix this error, make sure you are passing the correct object to the 'match()' function and that the object has that property defined before trying to access it. Also, check if you have declared the variables properly and if they are initialized correctly before using them in your script.

If you need more help, it would be helpful to provide more information about the code on lines 287, 316, 314, and 434 of your Code.gs file so that I can give you more specific guidance on fixing the error.

Reply all
Reply to author
Forward
0 new messages