setTime is not a function

455 views
Skip to first unread message

Silvio Cesar Dos Santos Junior

unread,
Feb 24, 2021, 2:17:09 PM2/24/21
to Google Apps Script Community
Hi Guys

I am trying to make a script to update the time on calendar events, but i am having an error that i dont now how to solve, so i want to now if someone would now how to solve it.

The script receives the following informations from a spreadsheet connected to forms:

timestamp
name
email
emailstamp
oldDate
newDate

Use the oldDate and newDate variables to create the dates like:

Date colected from the spreadsheet:
oldDate = Mon Mar 01 16:00:00 GMT-03:00 2021
newDate = Wed Mar 03 16:00:00 GMT-03:00 2021

Dates created inside the script:
end_oldDate = Mon Mar 01 17:00:00 GMT-03:00 2021
end_newDate = Wed Mar 03 17:00:00 GMT-03:00 2021

using this:

var end_oldDate = new Date(oldDate);
end_oldDate.setHours(end_oldDate.getHours() + 1);

var end_newDate = new Date(newDate);
end_newDate.setHours(end_newDate.getHours() + 1);

Until this part the script is working fine, and he uses this dates trying to reschedule a event.

I am using conflicts to check with really has a event at the oldDate if it does he tries to set a new beginTime and endTime for this event

var conflicts = calendarID.getEvents(oldDate, end_oldDate);

Logger.log(conflicts);

if (conflicts.length == 1) {

//until here the script in working, what i am doing wrong ?

var event = conflicts.setTime(newDate, end_newDate);

Logger.log('Event ID: ' + event.getId());

} else {

page.getRange(lastRow, 7).setValue("Rejected");

}

This is the error:

TypeError: conflicts.setTime is not a function

Jean-Luc Vanhulst

unread,
Feb 24, 2021, 2:20:32 PM2/24/21
to google-apps-sc...@googlegroups.com
Hi Silvio,

getEvents() returns an array - so you probably would have to do conflicts[0].setTime() ?


--
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/4ab40b4d-a181-4a27-b3bd-56f619e3ed06n%40googlegroups.com.

Silvio Cesar Dos Santos Junior

unread,
Feb 24, 2021, 2:24:14 PM2/24/21
to Google Apps Script Community
It worked, i had no idea that would be so simple i started to programming last year.

Thank you, you helped me alot.
Reply all
Reply to author
Forward
0 new messages