Google Apps脚本 - 使用约会颜色创建日历活动

时间:2018-05-07 14:57:06

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

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

以下是现在正在修改的代码!

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

1 个答案:

答案 0 :(得分:-1)

calendarEvent.setColor不适合你吗?

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

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

event.setColor(CalendarEvent.EventColor.RED)?

相关问题