Matthew Kelsch
Matthew Kelsch

Reputation: 11

Google Sheets to Google Calender

I am attempting to transfer information from google sheets to google calendar but the script I put in keeps saying:

"Exception: The parameters (String,String) don't match the method signature for CalendarApp.Calendar.createEvent. shopSchedule @ Code.gs:31

I have very little experience with coding, and I am following the coding of another person, expect with my own variables, but I'm not sure what went wrong.

Here is overall script:

    function shopSchedule() {
  /**
      Task 1) Open The Event Calendar.
   */
var spreadsheet = SpreadsheetApp.getActiveSheet();
var calendarId = spreadsheet.getRange("A52").getValue();
var eventCal = CalendarApp.getCalendarById(calendarId);

/**
      Task 2) Pull the schedule information into the code, in a form that the code can understand.
 */
var signups = spreadsheet.getRange("A1:E2").getValues();

/**
      [
        [8/20/2021, Completion Date],
        [8,27,2021, Shipping Date]
      ]
 */

 /**
      Task 3) Do the work!
  */
  for (x=0; x<signups.length; x++) {

    var shift = signups[x];

    var jobName = shift[0];
    var jobDate = shift[1];

    eventCal.createEvent(jobName, jobDate);
  }
}

Upvotes: 1

Views: 151

Answers (2)

Cooper
Cooper

Reputation: 64032

Try this:

function shopSchedule() {
  const ss = SpreadsheetApp.getActiveSheet();
  const cal = CalendarApp.getCalendarById(ss.getRange("A52").getValue());
  const signups = ss.getRange("A1:E2").getValues();
  for (x = 0; x < signups.length; x++) {
    let shift = signups[x];
    let jobName = shift[0];
    let jobDate = new Date(shift[1]);//This will accept a lot of strings but if not you may need to extract the correct data from the string and use a date constructor
    let endDate = new Date(jobDate.getFullYear(),jobDate().getMonth(),jobDate.getDate(),jobDate.getHours() + 1);
    cal.createEvent(jobName, jobDate, endDate);
  }
}

Date() Constructor

Note: the monthIndex is a number from 0 to 11 not 1 to 12

Upvotes: 1

Lle.4
Lle.4

Reputation: 606

You are using the line eventCal.createEvent(jobName, jobDate), the last line of your code. But I think you're actually trying to make an all-day event, in which case you would want to use eventCal.createAllDayEvent(jobName, jobDate). You can see documentation for that here. (createEvent would require additional parameters, specifically both a start and end time.)

Upvotes: 0

Related Questions