I have a problem regarding the changing of dates of a Google Calendar Event series. The API doesn't have any methods for changing the dates.
Is there a way I can do this? I am creating a form where when you edit the due date of the request in the spreadsheet, it will also edit the calendar event series.
Your statement is incorrect it is possible to change or update the date of a Google calendar event using the Google Calendar API.
Option nr 1:
You can patch the event in the body you include the variables you would like to update or patch. In this case date.
Events: patch Updates an event.
Request
PATCH https://www.googleapis.com/calendar/v3/calendars/{calendarId}/events/{eventID}?key={YOUR_API_KEY}
{
"start": {
"dateTime": "2008-09-26T12:01:00+02:00"
}
}
Response
200 OK
Option nr 2
Another option would be to first use Events.get to get the event change what you need then do events.update. This will do an update on everything in the event. While Patch just changes one what you need.
Related
I am using the attached to automate a time entry to go along with the date for a calendar import. The entries don't have times, and the staff will not enter them try as I might. I need to automate them to simplify the entry procedure.
The issue I am facing is that the Calendar API needs the data to be in DATE/TIME format. To do this I need to use the =DATE+TIME formula. When I do so and the time reaches 12:00AM, the dates thereafter change to the following day.
Essentially I need to either override the logic that makes it move into the next day after midnight appears, or I need to tell either the function in column B-C that it can never roll to midnight. I am trying to think of perhaps a way that I can tell the function to reset the time if the date in column A changes to a new day, and if it doesn't change to a new day go ahead and use the existing function and add 5 minutes to the time that is shown previously to it.
I am stumped, any help would be greatly appreciated.
Here is a sheet to show you the issue
Here is the formula I tried, which worked to sort out the problem but did not work with the Calendar API requirements to format at DATE/TIME. Even when using the importrange formula to move the data into a new sheet with the cells formatted as DATE/TIME it still recognizes it as TEXT as this is what the formula prescribes.
=IF(A2<>"",(CONCATENATE(TEXT(A2,"MM/DD/YYYY")&" "&TEXT(B2,"HH:MM:SS"))),"")
I need this to work in both the sheet and in the import to Calendar using the Calendar API requirements through APPScript.
If I understood correctly your question, here a suggestion with a custom Apps Script function called like a normal Google Sheet function.
Open Apps Script Editor and paste the function below
Call the function rebuildDateTime(COL1, COL2) inside your spreadsheet
Spreadsheet:
Code:
function rebuildDateTime(arg0, arg1) {
var date = new Date(arg0);
var str = arg1.toString().split(':');
date.setHours(str[0]);
date.setMinutes(str[1]);
return date;
}
Warning :
Your COL2 (which contains only the time), must be forced to TEXT FORMAT
References :
Create a custom function
If I have the event ID of a Google Calendar event, for example:
4htgpmm1hmak744r0kbkdcodar#google.com
How can I construct a URL to view the event details in the Google Calendar interface?
For example, if I go to a google calendar event, I see a URL such as this:
https://calendar.google.com/calendar/r/eventedit/NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
What function/algorithm can I run to go from 4htgpmm1hmak744r0kbkdcodar#google.com to NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw?
Bonus: A bonus would be if there was also a shortcut method that worked on a CalendarEvent via Google Apps Script. For example, if there was a method such as getUrl() just like there is a getId() method.
Since the same event can exist in multiple calendars (e.g. by inviting others to it), the event id is not sufficient information.
To construct a URL you need both the event id (refresher for how find it), AND the Calendar ID (see below for instructions as to how to find it). You'll then need to encode both as base64, and finally you'll you have a valid Google Calendar event link.
For the following instructions, imagine we have an event, Event1, and it exists in both calendars, CalendarA and CalendarB.
In the Google Calendar interface, you would be able to view any of these combinations:
Event1 in CalendarA
Event1 in CalendarB
Let's assign the following IDs:
Event1 ID: 4htgpmm1hmak744r0kbkdcodar#google.com
CalendarA ID: eugu9kan1ddi1pmi6sk3ib56g#group.calendar.google.com
CalendarB ID: afd3zeuguoepmi32s5i56g#group.calendar.google.com
To construct an event URL:
Get the event-id, which is the event id without the #google.com
E.g. for Event1 we have 4htgpmm1hmak744r0kbkdcodar
Get the calendar-id, which is the calendar id with the #group.calendar.google.com replaced with #g
E.g. for CalendarA we have eugu9kan1ddi1pmi6sk3ib56g#g
Join the two values with a space in the middle.
<event-id> <calendar-id>
E.g. for Event1 + CalendarA, we have:
4htgpmm1hmak744r0kbkdcodar eugu9kan1ddi1pmi6sk3ib56g#g
Encode the value as base64 (e.g. on https://www.base64decode.org):
NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw==
Remove the training ==:
NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
You can now append this value to https://www.google.com/calendar/event?eid= (view event page) or https://calendar.google.com/calendar/r/eventedit/ (edit event page):
https://www.google.com/calendar/event?eid=NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
or
https://calendar.google.com/calendar/r/eventedit/NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
You're done! That URL will take you to the calendar event in the Google interface.
How to find the calendar ID
If you need instructions for how to find the calendar id...
To find the calendar ID:
Go to the calendar settings
Scroll down until you find the calendar id field.
This might be a value that ends with #group.calendar.google.com, your email address, or some other value.
If you are having trouble finding the calendar id, another tool that might help is adding the eventdeb=1 parameter to the URL, going to the Troubleshooting info of an event, and then looking for either the organizer or participant values, both of which contain calendar ids.
In Apps Script
var eventUrl = "https://www.google.com/calendar/event?eid=" +
Utilities.base64Encode(event.getId().split('#')[0] +
" " +
event.getOriginalCalendarId())
.replace(/\=/g, '');
#Senseful had was a super helpful answer, and it works!
A few important things to note adding to the above. Firstly, when base64 encoding, you'll end up with a == at the end, remove that
Second, the base calendar URL will not work when the calendar the event belongs to does not belong in the primary account the user is logged in with. For example, if you're logged into 3 accounts, you'll have a different URL for each one e.g.
https://calendar.google.com/calendar/r/...
https://calendar.google.com/calendar/b/2/r/...
https://calendar.google.com/calendar/b/3/r/...
and so on... I don't think there's a solution that'll help with this situation since it's impossible to predict what accounts a specific user is logged into at any time.
I have a time log form that has a date field I do not want to have to fill out every time as 90% of the time the date would be today's date. (Sometimes you will be entering something from another day and need to change it).
When an entry is added column A is always going to have something, so it should check to see if A is empty and if that same rows D is empty it will input today's date into D.
Some of the example's I have looked at were for onEdit of cell change it, but I could not get it to work with a form submit or even just have it automatically check all the cells in D and if empty put today's date (Only when B has value).
I have a function to sort the sheet right now that is called when on form submit/onEdit happens and would like to stick the new formula in the bottom of the same one (unless that is bad practice). The reason for this is less functions to have to add to the trigger list.
A: Timestamp | B: What | C: Paid? | D: Date
You can try using Date from Google spreadsheets function list which Google Sheets offers.
And, as mentioned in Custom Functions in Google Sheets, if the available functions aren't enough for your needs, you can also use Google Apps Script to write custom functions then use them in Google Sheets just like a built-in function.
To get started, guidelines for custom functions and samples can be found in the given documentations.
You can use Google Apps Script with onFormSubmit trigger which will populate the said cell with default date.
Here is a sample code which will populate the current date in Column 4 of the row in question.
function onFormSubmit(e) {
//edit responses sheet name
var responseSheetName = 'Form Responses 2';
//Edit colmn number, column in which the date has to be autopopulated
var column = 4;
//Get target row number
var row = e.range.rowStart;
//If no date, pouplate the cell with current date
if(!e.values[column-1]){
SpreadsheetApp.getActive().getSheetByName(responseSheetName).getRange(row, column).setValue(new Date())
}
}
In order to setup the above code, open the Spreadsheet which contains the form responses. Go Tools > Script Editor. This will open script editor window. Paste above code and edit the responseSheetName and column . Now Save it.
After saving it, setup an on form submit trigger.
To setup the trigger, follow these steps.
From the script editor, choose Resources > Current project's triggers.
Click the link that says: No triggers set up. Click here to add one now.
Under Run, select the name of function onFormSubmit which you want to trigger.
Under Events, select From spreadsheet.
Select On form submit
Optionally, click Notifications to configure how and when you will be contacted by email if your triggered function fails.
Click Save.
I am fairly new to Google Script and I have come across an issue.
I would like to submit a different value to the label of the multiple choice option selected.
I am writing a script that generates a form to signup for any one of the events happening with in the next two weeks. These events are pulled from a calendar. For disambiguation reasons I am adding the event date to the event name before adding the array to the MulipleChoice item list.
I want to submit the Event ID rather than the newly created name as it will make the script's management of the responses so much simpler.
Hence This is what the multiple choice list would look like:
[] Event 1 20/06/14
[] Event 2 22/06/14
[] Event 3 23/06/14
[] Event 4 27/06/14
[] Event 5 29/06/14
Then If the user selects Event 2, I would like the value submitted to the responses spreadsheet to be Event 2's ID rather than "Event 2 22/06/14".
Please help me!
Maybe you could use an easier way:
Create a sheet where you store Events name and corresponding ID.
Then add a column in your answer sheet which will get the ID corresponding to the event name using either a script or ARRAYFORMULA + Vlookup
Hope this help,
I have a script that takes event information for google sheet and adds them into a specified google calendar. So far everything works fine except when I try to create an all day event that spans multiple days. The scenario that I am fighting with is for vacation. If I create the event manually, I can choose "All day" and set a start and end date of two different days. Note, "Repeat..." is not used. Visually the event spans the days specified. This is what I want to duplicate with my script.
As far as I can tell, the API only provides:
calendar.createEvent(title, startTime, endTime)
which creates a non-all day event that does span days, but it shows the start time which is not what I want. The event is truly and all day event.
calendar.createAllDayEvent(title, date)
which creates and all day event for only one day.
What seems to be missing is
calendar.createAllDayEvent(title, startDate, endDate)
which is what is discussed here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=952, but there isn't any significant movement on the issue.
A possible work around is discussed here: How to create two days AllDay Event with Google Apps Script?. The problem is creates what looks like multiple single all day events. I want the multi day to show up as spanning multiple days.
Has anyone found any other work around?
You can use createEventFromDescription(), it works perfectly for "n" full days.
var start = Utilities.formatDate(new Date(date_from), "GMT"-0500, "MM-dd-yyyy");
var end = Utilities.formatDate(new Date(date_to), "GMT"-0500, "MM-dd-yyyy");
var vacationCalendar = CalendarApp.getCalendarById(CALENDAR_ID);
vacationCalendar.createEventFromDescription(title+" "+start+"-"+end);
Edy's suggestion of createEventFromDescription() is nice and clean, +1.
With that being said, if you need more fine-grained control over the event and have a lot of metadata you're trying to set (such as location, description, attendees, etc), I would recommend using the new version of the Google Cal API aka "Advanced Calendar Service", which natively supports multiple-day all-day events.
Basically looks like this:
// end dates are exclusive, so this creates a 2-day event
// starting on the 9th and ending on the 10th
var event = {
summary: 'My Event',
start: {
date: '2015-04-09' // unfortunate it doesn't seem to accept JS Date() objects :(
},
end: {
date: '2015-04-11'
}
};
event = Calendar.Events.insert(event, calId);
For what it's worth, "use this new API" is also the answer given by a google dev on the issue ticket mentioned in the original description of this StackOverflow post.