'This works on one account but not another. What could cause this?
These functions run individually, createSchdMedEvents and createUrgentMedEvents run when a form is submitted. The third createEvent function is set to run when a ui element is clicked. Everything seems to be working fine on my own Google account. But, when I put the code into the duplicate spreadsheet associated with my work account, it doesn't create the events in the Google calendar.
//Function to submit sheet data to Calendar Event
const eventDuration = 3;
const calendarTrans = CalendarApp.getCalendarById("[email protected]");
const calendarMedical = CalendarApp.getCalendarById('[email protected]');
//Function to create Urgent Care entry to Medical Calendar
function createUrgentMedEvents() {
const ws = SpreadsheetApp.getActiveSpreadsheet();//
const ss = ws.getActiveSheet();
for (var i = 2; i <= ss.getLastRow(); i++) {
const created2 = ss.getRange(i, 4).getValue();
const schdMed = ss.getRange(i,15).getValue();
if (created2 == "Urgent Care"){
//const schdMed = ss.getRange(i, 15).getValue();
const eventName = ss.getRange(i, 4).getValue(); // Title
const location = ss.getRange(i, 8).getValue(); // Destination
const rider = ss.getRange(i, 3).getValue(); // Rider
const date = ss.getRange(i, 9).getValue(); // Ride Date and Departure time
const apptTime = ss.getRange(i, 10).getValue(); // Appointment Time
const returnTime = ss.getRange(i, 11).getValue(); // Return Time (Depart Location to return to WH)
const hoursMinutes = date.getHours() + ':' + date.getMinutes(); // Time of departure for Description Text
const phone = ss.getRange(i, 7).getValue(); //Phone Number
var startingDate = new Date(date)
var endingDate = new Date(date)
endingDate.setHours(startingDate.getHours() + eventDuration)
calendarMedical.createEvent('Driver ?, ' + rider + ' ' + eventName + ', Depart WH @'+hoursMinutes, startingDate, endingDate, { location: location, description: 'Driver:\n \nRider:\n' + rider + ', ' + phone + '\n' + '\nDepart WH@ ' + hoursMinutes + '\nAppointment Time: ' + apptTime + '\nDepart Appointment @ ' + returnTime })
ss.getRange(i, 15).setValue("Medical Created")
}
else if(schdMed == "Medical Created")
{break;}
}
}
//Function for Scheduled Medical Event to Medical Calendar
function createSchdMedEvents() {
const ws = SpreadsheetApp.getActiveSpreadsheet();//
const ss = ws.getActiveSheet();
for (var i = 2; i <= ss.getLastRow(); i++) {
const created2 = ss.getRange(i, 4).getValue();
const schdMed = ss.getRange(i,15).getValue();
if (created2 == "Scheduled Medical") {
//const schdMed = ss.getRange(i, 15).getValue();
const eventName = ss.getRange(i, 4).getValue(); // Title
const location = ss.getRange(i, 8).getValue(); // Destination
const rider = ss.getRange(i, 3).getValue(); // Rider
const date = ss.getRange(i, 9).getValue(); // Ride Date and Departure time
const apptTime = ss.getRange(i, 10).getValue(); //Appointment Time
const returnTime = ss.getRange(i, 11).getValue(); //Return Time (Depart Location to return to WH)
const hoursMinutes = date.getHours() + ':' + date.getMinutes(); // Time of departure for Description Text
const phone = ss.getRange(i, 7).getValue(); //Phone Number
var startingDate = new Date(date)
var endingDate = new Date(date)
endingDate.setHours(startingDate.getHours() + eventDuration)
calendarMedical.createEvent('Driver ?, ' + rider + ' ' + eventName + ', Depart WH @'+hoursMinutes, startingDate, endingDate, { location: location, description: 'Driver:\n \nRider:\n' + rider + ', ' + phone + '\n' + '\nDepart WH @' + hoursMinutes + '\nAppointment Time: ' + apptTime + '\nDepart Appointment @' + returnTime })
ss.getRange(i, 15).setValue("Medical Created")
}
else if (schdMed == "Medical Created")
{break;}
}
}
//Function to create General Transportation Event in Passenger Van Calendar
function createTransportationEvents() {
const ws = SpreadsheetApp.getActiveSpreadsheet();//
const ss = ws.getActiveSheet();
for (var i = 2; i <= ss.getLastRow(); i++) {
const created1 = ss.getRange(i, 14).getValue();
const created2 = ss.getRange(i, 4).getValue();
if (created1 != "Event Created") {
const eventName = ss.getRange(i, 4).getValue(); // Title
const location = ss.getRange(i, 8).getValue(); // Destination
const rider = ss.getRange(i, 3).getValue(); // Rider
const date = ss.getRange(i, 9).getValue(); // Ride Date and Departure time
const apptTime = ss.getRange(i, 10).getValue(); //Appointment Time
const returnTime = ss.getRange(i, 11).getValue(); //Return Time (Depart Location to return to WH)
const hoursMinutes = date.getHours() + ':' + date.getMinutes(); // Time of departure for Description Text
const phone = ss.getRange(i, 7).getValue(); //Phone Number
var startingDate = new Date(date)
var endingDate = new Date(date)
endingDate.setHours(startingDate.getHours() + eventDuration)
calendarTrans.createEvent('Driver ?, ' + rider + ' ' + eventName + ', Depart WH @'+hoursMinutes, startingDate, endingDate, { location: location, description: 'Driver:\n \nRider:\n' + rider + ', ' + phone + '\n' + '\nDepart WH @' + hoursMinutes + '\nAppointment Time: ' + apptTime + '\nDepart Appointment/Lesson: @' + returnTime })
ss.getRange(i, 14).setValue("Event Created")
}
}
}
// Create a Button to schedule events
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu("📅 Submit")
.addItem("Transportation", "createTransportationEvents")
.addToUi();
}
Additionally, I'm getting TypeError: date.getHours is not a function createTransportationEvents @ Submit to multiple Calendars.gs:93 for the createTransportationEvents function. It looks the same as the other two functions. I know I'm missing something there. Very new to programming. Thank you for your help.
@TrauzerHamz
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
