I'm experiencing issues with my GAS script when trying to generate events, as it is unable to

Issue

After creating a script to generate events from specific emails, the script runs without errors but does not display any events on the calendar. I am confident in the code itself and suspect that there may be authentication settings needing configuration to properly create events.

Attempts to Resolve

  • Confirmed ability to read events via GAS.
  • Extracted desired emails using GAS.
  • Verified correct default calendar ID.

Code Snippet and Console Output

See below for the code snippet and console log.

function myFunction() {
 var event = CalendarApp.getDefaultCalendar().createEvent(
   "test", 
   new Date("2021", "02", "20", "10", "05"),
   new Date("2021", "02", "28", "10", "30"));
 console.log('Event ID: ' + event.getTitle() + ' is created');
}
5:52:52 PM  Notice  Execution started
5:54:17 PM  Info    Event ID: test is created
5:52:53 PM  Notice  Execution completed

Answer №1

Clarification / Problem

Your attempted event creation spans from February 20th to February 28th.

  • The main issue arises from incorrect definition of date objects.

It is worth noting that according to this resource:

JavaScript assigns numeric values to months from 0 (January) to 11 (December).

Hence, for the month of February, the second parameter in the new Date object should be 1, not 2. Currently, your code inadvertently sets up events for March.

If you have checked your calendar for March, chances are there are multiple events due to running the code repeatedly.

Resolution:

Amend:

new Date("2021", "02", "20", "10", "05"),
new Date("2021", "02", "28", "10", "30")

To:

new Date("2021", "01", "20", "10", "05"),
new Date("2021", "01", "28", "10", "30")

Remember, parameters can also be integers instead of strings:

function myFunction() {
 var event = CalendarApp.getDefaultCalendar().createEvent(
   "test", 
   new Date(2021, 01, 20, 10, 05),
   new Date(2021, 01, 28, 10, 30));
 console.log('Event ID: ' + event.getTitle() + ' has been successfully created');
}

Additional Tip:

You can verify your date objects by using console.log. For instance, if your current code generates dates for March:

function myFunction() {
  console.log(new Date(2021, 02, 20, 10, 05));
  console.log(new Date(2021, 02, 28, 10, 30));
}

this will output:

https://i.sstatic.net/PLOfh.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

build a key-value pair collection in Angular 2

Struggling to figure out how to create an associative array in Angular2? I've attempted the following: onSubmit(){ let inputfield:any[] = []; for(var i=0; i<this.inspectionform.value["inputfileds"].length; i++){ if(this.inspectionform.valu ...

What's causing my variables to be returned as null in the alerts?

Why am I receiving null values when alerting my variables? I'm attempting to pass a string stored in a variable from an external JavaScript file back to the main page using alerts. Initially, I suspected that the JavaScript was not fetching data cor ...

Tutorials on transferring selected option data to a component

My JSON data is structured like this: Whenever I choose an option, I want to pass the values (code and description) from the JSON object to the component. nameList= [ { "code": "1", "description": "abc" }, { "code": "123", "descript ...

Conceal form upon submission with jQuery

Is it possible to have a html form inside a table and then hide it once the form is submitted? The Form: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <tr> <td colspan="3"> <h ...

Troubleshooting AJAX issues in Firefox with window.location.assign function

Here is my AJAX POST request that sends serialized form data to the server: // Handle form submission. $('#evaluationform').on('submit', function(e){ e.preventDefault(); ajaxObject = { url: $("#evaluationform").attr("a ...

Dynamic binding issue causing audio event to not fire

Currently, I have an <audio> element that is playing audio. When I manually add the event listener onplay in the HTML code, it functions as expected. <audio onplay="alert('t')" .... It's working... However, when I attempt ...

Struggling to get the jQuery resize event to function properly

Ensuring that my charts remain responsive on different devices has been quite a challenge. Despite implementing a resize event handler in my function to dynamically adjust the charts, I encountered an issue where the page would go blank upon resizing the b ...

Test the history of React components using TypeScript without making any modifications to the component itself

I'm looking to write a test for my simple NotFound.tsx component. Here is the code: import React from "react"; import {Button} from "devextreme-react"; import "./NotFound.scss"; import {useHistory as UseHistory} from &quo ...

Stealthy Google Recaptcha integrated with a dynamic AJAX form

My website includes an ajax form: <form id="my_form"> <input type="text" id="field1" /> <input type="submit" value="submit" /> </form> I also have this JavaScript code: document.getElementById("my_form").onsubmit = fu ...

How can I pass an Angular parameter to an onclick function?

Let's dive in... I am dealing with a controller $scope.selectedScript = {}; $scope.selectedScript.scriptId = null; $scope.selectScript = function(script, index) { $scope.selectedScript = script; ...

JavaScript query: Why does code return NULL in Internet Explorer but functions correctly in FireFox?

In my external .js file, I have successfully linked this function... function SubmitAge(age, UpdatePanelID, HiddenAgeID) { $get(HiddenAgeID).value = age; __doPostBack(UpdatePanelID); } I am triggering it from an onClick event of an a href="#" tag. ...

When debugging tests in VSCode Mocha with typescript, the debugger follows through the transpiled file rather than the original source .ts file

Whenever I initiate the debugging process for my mocha tests with the provided configuration, Visual Studio Code ends up navigating through the transpiled code rather than the original TypeScript code. Is there a specific setting that needs to be adjuste ...

Finding Text Between Two Distinct Strings Using Regular Expressions in JavaScript

I am currently utilizing AJAX technology. My approach involves sending a GET request that retrieves a raw HTML string representing the content of a webpage. I am grappling with the challenge of isolating all elements enclosed between div tags: <div ro ...

How come ng-class doesn't apply to a specific class name?

I recently wrote the following code: <style> .dotted { border:dotted; } </style> .... <p ng-style="mystyle" ng-class="dotted">{{ answer }}</p> My intention was to have the paragraph element enclosed within a ...

Identifying Disconnected Sockets in Socket.IO

Running a socket.io server/client setup, I encounter an issue where a client safely disconnects, the server-side code snippet socket.on('disconnect', function() { }); is triggered as expected. However, in case of a client server crash, the ev ...

Wrapping an anchor tag with a div in Codeigniter

Can a div tag be used inside an anchor function? I have a div with the following CSS: #first{ opacity:0; } Now, I want to include it in my anchor element. Here is the code snippet: <?php if(is_array($databuku)){ echo '<ol>&l ...

Customizing the "Actions" Dropdown in APEX Interactive Grid

Is there a way to modify the choices available in the Selection section of a Row Actions Menu in Apex? I managed to alter the options in the Line Menu, but I'm facing challenges when trying to make changes in the Selection Menu. The Selection Menu i ...

filling out a form with data retrieved through an ajax request

After retrieving JSON data from an MVC controller, I am attempting to populate a form with this data but encountering difficulties. The returned data consists of only one row with three properties. Despite confirming that the data is being returned success ...

What is the best way to exit a for loop in jQuery?

let intervalTime = 800; for(let index = 1; index < 20; index++) { $("#slide"+index).delay(intervalTime).fadeIn(); intervalTime = intervalTime + 800; } Every time I click on a button, the value of "i" should reset to "0". I h ...

Is there a way to assign the value of a textfield to a session attribute in JSP prior to rendering?

Imagine I have the following code snippet: <html> <head> <script> function setSession() { var roll=document.getElementById("rollno").value; session.setAttribute("rollno", roll); } & ...