eventOpenTrigger - Google appsscript only fire's the first time - google-apps-script

Trying to build an addon for Google Calendar. When I first click on an event it triggers the eventOpenTrigger function. This works as expected.
If I click on another event again eventOpenTrigger triggers. If I then again click on the original event then eventOpenTrigger is not fired. Is this by design? Seems like this only triggers once for each unique event. I would like to update some information in the card every time the event is clicked on.

unfortunately there is no refresh from code, the action is bound to "eventOpenTrigger" when the calendar event is opened, if you want to re-run the function onCalendarEventOpen(event) you need to create an action such as
var action = CardService.newAction()
.setFunctionName('onCalendarEventOpen')
.setLoadIndicator(CardService.LoadIndicator.SPINNER)
you can provide a refresh button and add this action to button click, only this way i was able to get the event data that is required, if you do not want any event data and just need to call this function you can return onCalendarEventOpen from another and use calendar api to fetch the event details
const eventFromAPI = Calendar.Events.get(calendarId, eventId);
this is the only work-around i have been following

Related

onChange trigger is not firing sometimes

onChange trigger may not fire under the following conditions. Do you know the cause and the remedy?
Check the checkbox in the spreadsheet
Select Spreadsheet list
I just created it like this.
Create an empty spreadsheet
Rewriting the default code
function myFunction (event) {
event.source.getActiveSheet().getActiveRange().setValue(false);
}
Create onChange trigger
Create a checkbox in cell A1
Check the check box (about once in 10 times, the process is not executed and it is not displayed in Executions)
Onchange not firing
Yeah creating an empty spreadsheet is kind of a problem since the new container won't have a trigger inside of it's project. There are no events that fire upon the editing of script in the script editor. Yeah creating an onChange trigger that's not covered either I would not hold my breath on that one. But if you must have it then make it a feature request. That's enough for me for one question.

g-suite Google Calender Apps script On Event Save/Update

First of all, i am new to Google Workspace and this is the first time i am developing an addon.
I am trying to develop a Google Workspace(gsuite) Addon using Google Apps Script,
My main objectives are:
Whenever i create/save/update an event in Google Calender, i want to make an alert asking for ok and cancel, if i click cancel the event should not be created and if i click ok then the event should be created and the script function should call my API endpoint with the following parameters:
{
summary: summary_of_the_event,
created: event_created_or_updated_date,
googleCalendarId: calender_id
}
Here is the reference to Apps script Google calender:
https://developers.google.com/apps-script/reference/calendar/calendar-app
I appreciate the help.
Some thoughts about calendar add-ons
CalendarApp features the installable calendar trigger with the specification:
Calendar triggers fire when a user's calendar events are updated (created, edited, or deleted).
Installble triggers can be used in Google Workspace add-ons
Howver, this installable trigger only fire after the event has been created / updated, so it can help you to cancel event creation, but rather no manually delete the event a posteriori.
Mind also that the when the trigger fires, it does not give you any information about the created / updated event - you have to manually find this event e.g. by querying for the least created / updated event in user's calendar.
Google Workspace Calendar add-ons feature the manifest trigger for updating calendar events calendar.eventUpdateTrigger
Thereby:
This trigger only fires if the user makes one or more of the following edits:
Adds one or more attendees.
Removes one or more attendees.
Adds or switches to a different conferencing solution.
Google Workspace Calendar add-ons also feature the manifest trigger calendar.eventOpenTrigger
It fires when you open an event (this is what you want!).
However, this work only for already existing events - not when a user opens the Calendar UI interface to create a new event
Instead of letting a user create / update events through the regular Calendar UI, you can use Card Service to create a custom add-on interface where the user can specify that he wants to create an event
Within the card interface, it is easier to implement an ok / cancel functionality (as a card) and then (in case "ok" is clicked) create an event for the user programmatically.

Modify calendar event fields from a calendar addon (before saving the event)?

I'm developing a Google Calendar addon.
I want to be able to modify event fields (e.g. the title) within the addon.
I have a function that runs when triggered by eventOpenTrigger.
According to the documentation, we can only addAttendees and setConferenceData. I tested those functions and they are working fine for both existing and new events.
Is there any proper way to modify other event fields?
I found a "dirty trick" to modify the event's title for an existing event using the CalendarApp API:
function onCalendarEventOpen(e) {
var calendar = CalendarApp.getCalendarById(e.calendar.calendarId);
var event = calendar.getEventById(e.calendar.id);
if (!event) {
// This is a new event still being created.
return createSimpleTextCard('A new event! Am I invited?');
}
event.setTitle('Modified title') // imagine doing this after a button click
return createSimpleTextCard('Modified title');
}
This trick has some drawbacks:
The event page's ui that we are currently editing is not refreshing accordingly; we have to close/open the event to see the changes. Plus, if the user make any change on the modified fields, it keeps his version. Is there any way to force a "refresh" of those fields so that the user can see an up-to-date version of the event?
It doesn't work with new events (for which we have no valid ID when querying the API) which would be very annoying for the addon I'm developing.
Does someone have a better solution? Am I missing something? It would be awesome to have a function setTitle that works the same way as addAttendees on a CalendarEventActionResponseBuilder.

Google forms script on form submit - event does not have FormResponse object

I have a google form, and have added a script to it.
I created a function:
function myFunction(e)
{
Logger.log(e);
}
Then I went to Edit > Current Project Triggers
I added a new trigger, selecting myFunction, and the following settings:
Select Event Source = From Form
Select Event Type = On form submit
When I submit the form and check the logs, I see:
{authMode=FULL, source=Form, triggerUid=25580}
It does not have a response object
I have a number of other forms set up and are working and allow me to use the response object. I haven't created a form in a while - and now I can't get them to work. I've set them up the same as the others as far as I can see.
Any idea as to why I am no longer able to access the response object on the event?
This is a bug - I submitted an issue in the Tracker as suggested. They have given a workaround until they fix it.
https://issuetracker.google.com/u/2/issues/118921815

Google App Scripts - Create Google form using CreateForm() function and run MarkForm() function on form submit

Aim
I am currently using Google App Scripts to create a form that one submitted sends an email to the respondent with a detailed summary of their results.
Methods so Far
To achieve this, I have written two functions: one function to create the form and a second function to mark and email the summary of the results to the respondent.
function CreateForm(){
//Working code to create form here
}
function MarkForm(){
//Working code to create and email detailed summary of results
}
In order to make this code work correctly, I have to:
Create the form using the CreateForm() function
Open the new form and paste the MarkForm() function into the script editor.
Set a trigger OnFormSubmit to run the function MarkForm()
Question
Is it possible to do the three steps above using one function?
You can use the "On Form Submit" installable trigger to run a function when a form response comes in. Reading the Google Triggers guide in the Apps Script Documentation will help.
Do the following:
Choose Edit > Current project's triggers. You see a panel with the message No triggers set up. Click here to add one now.
Click the link.
Under Run, select the function you want executed by the trigger. (MarkForm())
Under Events, select From Spreadsheet.
From the next drop-down list, select On form submit.
Click Save.
Now, when a submission comes in, the form response will be marked automatically. This trigger is an installable trigger, which means it needs to be set up through the menu rather than calling a function like onEdit().