Home > Enterprise >  Changing the Color of the Events in Google Calendar by Checking Google SpreadSheet Column with Value
Changing the Color of the Events in Google Calendar by Checking Google SpreadSheet Column with Value

Time:09-25

The below code works perfectly, now i need to change the color of the calendar events conditionally. I'm new to this coding. Can anyone edit this code for me please....

function CreateEvent() {
  var sh=SpreadsheetApp.getActiveSheet();
  //var calendarId = spreadsheet.getRange('***<LINKTOCELLTHATHASCALENDARID>***').getValue();
  var eventCal = CalendarApp.getCalendarById('YOUR_CALENDAR_ID');
  var drg=sh.getRange(2,1,sh.getLastRow()-1,7);
  var dA=drg.getValues(); 
  var crg=sh.getRange(2,6,sh.getLastRow()-1,1);//save that event was created in column G
  var cA=crg.getValues();
  for (i=0;i<dA.length;i  ) {
    var shift=dA[i];
    var title=shift[0];
    var startTime=shift[1];
    var endTime=shift[2];
    //var guests=shift[3];
    var description=shift[3];
    var location=shift[4];  
    if(!shift[5]) {
      var event={'location': location,'description': description  ',','sendInvites': 'True'}
      eventCal.createEvent(title, startTime, endTime, event)
      cA[i][0]="CREATED";//keeps this event from being created again
    }
  }
  crg.setValues(cA);
}

CodePudding user response:

Assuming the value is in Column G:

      var e = eventCal.createEvent(title, startTime, endTime, event);
      var b = shift[6];
      if (b === 'YES') { e.setColor(CalendarApp.EventColor.GREEN); }
      if (b === 'NO') { e.setColor(CalendarApp.EventColor.RED); }

References:

setColor(color)

Enum Color

  • Related