【问题标题】:Google Apps Script - Creating Calendar Events with Appointment ColorGoogle Apps 脚本 - 使用约会颜色创建日历事件
【发布时间】:2018-05-07 14:57:05
【问题描述】:

所以我有一个脚本可以很好地创建日历事件,我现在尝试将约会颜色设置为红色,但没有成功。做这个的最好方式是什么?这是我目前正在使用的代码的一部分。

这是现在可以运行的修改后的代码!

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;   
}

【问题讨论】:

  • 您的代码甚至没有尝试设置颜色...那么问题出在哪里?日历服务中提供的方法是否不允许您完全按照您的意愿行事?

标签: google-apps-script google-calendar-api


【解决方案1】:

calendarEvent.setColor 不适合你吗?

https://developers.google.com/apps-script/reference/calendar/calendar-event#setColor(String)

在您上面的代码中,您是否尝试过添加:

event.setColor(CalendarEvent.EventColor.RED)?

【讨论】:

  • 谢谢!以下让它工作。 event.setColor("11")
猜你喜欢
  • 2014-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多