1

I am making a google apps script and i am trying to make a program that would read the first callendar event. The problem is, when I try to get anything from it it just writes:

function () { [native code] }.

I have seen some questions written for javascript, but i dont understand, how to add jquery to apps script and i am not sure if it would fix anything.

var now = new Date();
var today = new Date(now.getTime());
var events = CalendarApp.getDefaultCalendar().getEventsForDay(today);
Logger.log(events);
var event1 = events[0];
Logger.log(event1);
var startTime = event1.getStartTime;
Logger.log(startTime);
var id = event1.getId
Logger.log(id)
var title = event1.getTitle
Logger.log(title)
}

1 Answer 1

5

Explanation:

  • The reason you are getting function () { [native code] } is because you are not executing the function. Namely, getStartTime, getId, getTitle are not properties but methods (functions). Therefore you need to add () at the end e.g. event1.getStartTime().

  • You can simply use var today = new Date() when specifying the date.

Solution:

function myFunction() {
  var today = new Date();
  var events = CalendarApp.getDefaultCalendar().getEventsForDay(today);
  var event1 = events[0];
  var startTime = event1.getStartTime(); //modified ()
  Logger.log(startTime);
  var id = event1.getId(); //modified ()
  Logger.log(id);
  var title = event1.getTitle(); //modified ()
  Logger.log(title);
}
1
  • Thanks a lot, now it makes sense, I thaught it was written in different programing language...
    – Maty Lojda
    Jan 20, 2021 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.