I'm writing a script that will add a series of events in my Google Calendar, invite a list of people to each one, and send a reminder 5 minutes before the event using the 'addEmailReminder(minutesBefore)' method. I used two friends as a test, and although they were successfully added to the event, the notification timers were all different.
I set minutesBefore to 5, but while I (the host) got the 5 minute reminder, the other emails had notifications automatically set to 10 and 30 minutes within the event on their calendar instead of the 5 that my code calls for.
Is this since Google likes to be smart and learn from your choices and automatically defaults to certain values?
code:
var addThisClass = myCalendar.createEvent(eventName, testStartTime, endTime,{guests: emailList, sendInvites: false});
addThisClass.addEmailReminder(5);
As you can see in the documentation:
Reminders are private information, specific to an authenticated user; they are NOT shared across multiple users.
So when you are setting the reminder via the .addEmailReminder(5) method, you are overriding only your private array of reminders. That's why your friends won't get any email notification.
Related
I am trying to create a Google calendar event for the user who submits leave request on google form. When this form response is recorded in google sheets, I get the user email id and want to create a calendar event for them. Script creates event when I use my email id, but it gives null when I try to do the same for other user.
Here is the sample code:
CalendarApp.getCalendarById(email)
.createAllDayEvent(
'OOO - Out Of Office',
startDate,
endDate,
{
description: message,
sendInvites: true,
});
I received this error: Cannot read property "createAllDayEvent" of null
I googled this error, and someone suggested that subscribing to user's calendar may solve this issue. I used the following snippet to counter that:
var calendar = CalendarApp.getCalendarById(email);
if(calendar == null){
//user may not have access, auto-subscribe them.
calendar = CalendarApp.subscribeToCalendar(email,{hidden:true,selected:false});
}
But it is showing a new error stating: The calendar or calendar event does not exist, it was deleted, or the user doesn't have access to it
Any idea how we can make it work. Thank you.
You can't do this on Form Response (at least not reliably).
To create an event in another user's calendar they must have changed their calendar settings to be available to the public and the Access Permissions must be set to 'Make changes to events'. More information about this can be read on this help page
If these settings aren't set by the user, you're out of luck creating events for them. In this case you have two options:
Create an OAuth2 Application which the user authenticates to allow the creation of Calendar events on their behalf (though this still can't be done on form submit)
Create an event on your calendar and send them an invitation using their email address. You can give them edit permissions to the event so that they have control of it as if it were in their calendar, though in this case they will have to accept the event invitation.
I'm building a two-way script to go back and forth between Google Sheets and Google Calendar, and I'm wondering how to tell whether a CalendarEvent has been deleted.
Currently, I store event IDs in the spreadsheet every time an event is created, then I use that event ID to read/write subsequent updates to that event:
var event = eventcal.getEventById(eventId);
But I don't see a way in the documentation to determine whether a CalendarEvent has been deleted in the calendar. Retrieving a recently deleted event using the method above simply returns the CalendarEvent since it lives in the Recycle Bin. event.getLastUpdated() is also too general for me since I'd like to do different things for updated/rescheduled events and deleted events.
Use Reports API instead
When listing the Activities for a specific App you can specify the eventName and filters parameters to look for deleted events given a certain Calendar.
References
Reports API > Aplication Name
Method: activities.list
Google Calendar > Delete Event
We're building a platform that fetches data from the AdWords accounts under our AdWords Manager account and saves the data onto BigQuery to be viewed online via nice charts and tables.
As you all know, Adwords numbers need a few days to stabilize. So, every day at 12am we need to refetch all the data for the past 2 weeks and overwrite the data we already have saved for these 2 weeks (we're basically updating the numbers we have).
Our AdWords manager account has 150+ accounts under it. So, when we run the script that fetches the data for all these accounts for the past 2 weeks, understandably, the script times out because it needs more than 65 minutes to be done with the task.
When we looked online for solutions, the only thing we could find was using the "executeInParallel" function provided by the Adwords Script. This should allow us to run a function on several accounts at the same time. Unfortunately, the "executeInParallel" function cannot be called on more than 50 accounts. Since we have 150+ accounts, we cannot call the "executeInParallel" function on them.
We tried splitting the accounts into groups of 50 and calling the "executeInParallel" function on these groups. However, the "executeInParallel" function cannot be called more than once in a single script. This means that we're not able to use this solution.
The only other solution we can think of is to create a script for each one of the 14 days and have each script would fetch the data of all the accounts for a specific day. So, Script1 would fetch the data for today -1. Script2 would fetch the data for today -2 ... Script14 would fetch the data for today -14.
Does anyone else have another solution that we can use?
I never used the adwords apps script service but I see it works with iterators so in apps script we are used to use that with Drive service. What I would do, based on this example script :
var accountSelector = AdsManagerApp
.accounts()
.withCondition("Impressions > 100")
.forDateRange("LAST_MONTH")
.orderBy("Clicks DESC");
var accountIterator = accountSelector.get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
}
What you can do :
You create a json object where you will store the account id treated.
You store this json in a script property, you have to use json.stringify in order to save the json as text in theproperty.
You use trigger to restart program before it goes over time limit.
Idea is :
You start the program
you initiate the json by getting the property, if empty create blank json
you initiate account selector
you start the while(), inside you test first before to get data if the account is already treated, i.e. have an entry in the json.
If not you get the data and once done you add an entry in the json
I recommend to do that for 10 account for example and not waiting time overdue
When 10 accounts are treated you go out the while (break;) to push the json in the script property
Last, you create a trigger to rerun the function after 90 seconds.
ScriptApp.newTrigger("myFunction")
.timeBased()
.after(90 * 1000)
.create();
Don't forget to delete triggers before to create a new one
Don't forget when you finish iterator to stop everything and reset property for newt run.
Stéphane
I have a Google App for Business.
Is it possible to access other user's calendar to input & retrieve event?
I only know how to do it for my own calendar, but not others.
I have super administrator access.
Yes, you can get any calendar by it's ID, and then just get the events. As per your comment I don't believe that it will allow you to get any calendar in the domain, you appear to need to be subscribed. Whether this is expected or not I'm unsure.
Enter the Advanced Calendar Service, which uses the Calendar API to manage your domains calendars (and I suspect is probably the correct way to go about managing your domains calendars). After you turn the calendar service on, you can do what your looking for simply like so:
function calendar(){
var cal = Calendar.Calendars.get('calendar#domain');
Logger.log(cal.summary);
};
Which will return the 'name' of the calendar. (Note: For primary calendars, the 'name' of the calendar is almost always the same as the calendar ID).
We are using Google Apps Premier and I just noticed a change in behavior with the CalendarApp.getCalendarById() function, but it must have changed in the last month or so since it was working before the Christmas break.
The previous behavior (12/2012 and before) with the CalendarApp.getCalendarById() function used to be one where a calendar object was always returned as long as the calendar resource existed. Now this function returns null unless the the user has subscribed to the calendar resource. In the testing that I have done, as long as I am subscribed I get a calendar resource object and as soon as I unsubscribe, I start getting a null object. I have not tested with regular user calendars and have only tested with resources (such as rooms).
var calendar = CalendarApp.getCalendarById(calendarID);
This is pretty annoying since I need to run scripts against many rooms which I do not want to be subscribed to. The current work around of subscribing to a room or calendar is not very workable.
This has always been the case. You must have previously been subscribed and not realized it. I assure you this code was not changed.