google-apps-script - Google Apps 脚本 - 使用约会颜色创建日历事件
问题描述
所以我有一个脚本可以很好地创建日历事件,我现在正试图将约会颜色设置为红色,但没有成功。做这个的最好方式是什么?这是我目前正在使用的代码的一部分。
这是现在正在工作的修改后的代码!
function createCalendarEvent(eventObject) {
//Get a calendar object by opening the calendar using the
//calendar id stored in the GLOBAL variable object
//var startTime = eventObject.startDate+" "+eventObject.startTime
//var endTime = eventObject.endDate+" "+eventObject.endTime
var calendar = CalendarApp.getCalendarById(GLOBAL.calendarId),
//The title for the event that will be created
title = eventObject.eventTitle,
//The start time and date of the event that will be created
startTime1 = moment(eventObject.startDate+" "+eventObject.startTime).toDate(),
//The end time and date of the event that will be created ---moved up
APLength = eventObject.AppLength1;
//an options object containing the description and guest list
//for the event that will be created
var comboDescription = title+" in "+ eventObject.county +" is interested in a "+eventObject.deckStyle+". The referral source was "+eventObject.referral+". "+" Their email address is "+eventObject.Cemail+"."+" They can be reached at "+eventObject.phone1+" "+eventObject.phone2+" "+eventObject.Gdescription+" "+eventObject.Qdescription;
var options = {
description : comboDescription,
guests: eventObject.Cemail,
location: eventObject.location,
};
if(APLength=="1 hour") {var endTime1 = moment(eventObject.startDate+" "+eventObject.startTime).add(1, 'h').toDate()};
if(APLength=="2 hour") {var endTime1 = moment(eventObject.startDate+" "+eventObject.startTime).add(2, 'h').toDate()};
//////Send a reminder email
//MailApp.sendEmail ("-----------", "New Appointment with "+title, "I have added the following information to your calender. The appointment range is "+moment(startTime1).format("dddd, MMM Do YYYY, h:mm:ss a")+" till "+ moment(endTime1).format("dddd, MMM Do YYYY, h:mm:ss a")+" See the following appointment details....."+comboDescription);
try {
//create a calendar event with given title, start time,
//end time, and description and guests stored in an
//options argument
//calendarEvent.setColor(11);
//eventObject.colorId: 11
var event = calendar.createEvent(title, startTime1, endTime1, options)
event.setColor("11")
//var event = Calendar.Events.insert(title, startTime1, endTime1, options)
//CalendarApp.event.setColor("10")
} catch (e) {
//delete the guest property from the options variable,
//as an invalid email address with cause this method to
//throw an error.
delete options.guests
//create the event without including the guest
//var eventObject.colorId = 11
//var event = calendar.createEvent(title, startTime1, endTime1, options)
var event = calendar.createEvent(title, startTime1, endTime1, options)
event.setColor("11")
//CalendarApp.event.setColor("10")
//var event = calendarEvent.setColor(11);
//colorId: Red
}
return event;
}
解决方案
calendarEvent.setColor 不适合您吗?
https://developers.google.com/apps-script/reference/calendar/calendar-event#setColor(String)
在上面的代码中,您是否尝试过添加:
event.setColor(CalendarEvent.EventColor.RED)?
推荐阅读
- android - 无法完成刷新条目的计划请求。客户端错误代码:3
- javascript - 如何在此处删除透明度
- python - 将python中混合数据类型对象中的数字转换为int/float,同时保持原样
- java - 如何区分私有实例变量和java中具有相同名称的参数
- ios - 在 iOS Swift 4 中使用 Realm
- linux - Android O 移植
- python - Python os.walk 仅包含特定文件夹
- python-3.x - Flask-SocketIO - 如何从子进程发出事件
- c# - .Net Core 2.0 与来自查询的 PostgreSQL 日期的区别
- javascript - JavaScript 匹配 unicode 字母