这适用于一个帐户,但不适用于另一个帐户。什么会导致这个?
This works on one account but not another. What could cause this?
这些功能 运行 分别 createSchdMedEvents
和 createUrgentMedEvents
运行 在提交表单时。当单击 ui 元素时,第三个 createEvent
函数设置为 运行。我自己的 Google 帐户似乎一切正常。但是,当我将代码放入与我的工作帐户关联的重复电子表格时,它不会在 Google 日历中创建事件。
//Function to submit sheet data to Calendar Event
const eventDuration = 3;
const calendarTrans = CalendarApp.getCalendarById("b9nlem0nd055i0003cktlkemlo@group.calendar.google.com");
const calendarMedical = CalendarApp.getCalendarById('7ct5c0angq01hti2i1na6h81c4@group.calendar.google.com');
//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();
}
此外,我得到 TypeError: date.getHours is not a function createTransportationEvents @ Submit to multiple Calendars.gs:93
用于 createTransportationEvents
函数。它看起来与其他两个函数相同。我知道我在那里遗漏了一些东西。非常新的编程。谢谢您的帮助。
@TrauzerHamz
它 return 作为字符串来自:
const date = ss.getRange(i, 9).getValue();
如果那是一个日期,把它变成一个日期对象:
const date = new Date(ss.getRange(i, 9).getValue());
那么你应该可以得到这个日期的小时数。
这些功能 运行 分别 createSchdMedEvents
和 createUrgentMedEvents
运行 在提交表单时。当单击 ui 元素时,第三个 createEvent
函数设置为 运行。我自己的 Google 帐户似乎一切正常。但是,当我将代码放入与我的工作帐户关联的重复电子表格时,它不会在 Google 日历中创建事件。
//Function to submit sheet data to Calendar Event
const eventDuration = 3;
const calendarTrans = CalendarApp.getCalendarById("b9nlem0nd055i0003cktlkemlo@group.calendar.google.com");
const calendarMedical = CalendarApp.getCalendarById('7ct5c0angq01hti2i1na6h81c4@group.calendar.google.com');
//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();
}
此外,我得到 TypeError: date.getHours is not a function createTransportationEvents @ Submit to multiple Calendars.gs:93
用于 createTransportationEvents
函数。它看起来与其他两个函数相同。我知道我在那里遗漏了一些东西。非常新的编程。谢谢您的帮助。
@TrauzerHamz
它 return 作为字符串来自:
const date = ss.getRange(i, 9).getValue();
如果那是一个日期,把它变成一个日期对象:
const date = new Date(ss.getRange(i, 9).getValue());
那么你应该可以得到这个日期的小时数。