简体   繁体   中英

Google Apps Script Calendar, my syntax with createEvent doesn't work anymore

The following syntax was still working two days ago, but not anymore. The execution log indicates that there was no problem but the appointment is not displayed in the calendars. This syntax exports several dozen appointments per day for a company. Could you help me?

function exportMeeting() {
  var calId = "myName@google.com";
  var cal = CalendarApp.getCalendarById(calId);

  var tstart = new Date('March 14, 2021 11:00:00 UTC');
  var date = new Date('March 14, 2021 11:00:00 UTC');
  tstart.setDate(date.getDate());
  tstart.setMonth(date.getMonth());
  tstart.setYear(date.getYear());

  var tstop =new Date('March 14, 2021 12:00:00 UTC');
  tstop.setDate(date.getDate());
  tstop.setMonth(date.getMonth());
  tstop.setYear(date.getYear());

  var desc="a description";
  var loc="a localisation";
  var gues="guest1@gmail.com, guest2@gmail.com";

  var newEvent = cal.createEvent("test appointment", tstart, tstop, {
    description: desc,
    location: loc,
    guests: gues
  });
}

Remark: in my original syntax, the date (March 14, 2021 12:00:00 UTC) comes from a google sheet cell

You are defining the start and end date at the same time. That doesn't make sense. I guess the problem will come from a change in the Spreadsheet document. If you show me the original code I can try to see where the problem is, right now it would be fixed if you left the dates as follows:

  var tstart = new Date('March 14, 2021 11:00:00 UTC');
  var tstop = new Date('March 14, 2021 12:00:00 UTC');

If you want to define two dates with Spreadsheet values, I recommend the following:

  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
  var startDate = ss.getRange('A1').getDisplayValue() // start cell
  var tstart = new Date(startDate)
  var endDate = ss.getRange('A2').getDisplayValue() // end cell
  var tend = new Date(endDate)

Make sure you get two different values for startDate and endDate . You can try a simpler example to start with:

  var date = 'March 14, 2021 11:00:00'.
  var tstart = new Date(date)

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM