Last year I found a Template based on Fullcalendar v3 and I costumize it based on the direction my boss gave me. Now I'm doing an upgrade to fullcalendar6 following the documentation but I'm having some trouble understanding
In my old code I had this var view = $('#calendar').fullCalendar('getView'); to get the view of the calendar, but I read that getView is deprecated and
In the V4 release it's written this
access the Calendar’s view property instead
But I couldn't find the equivalent-ish.
I need it to get the start of the month (for that I read that I need to change intervalStart to currentStart but I'm missing the view part):
My old code:
var view = $('#calendar').fullCalendar('getView');
var start = view.intervalStart._d;
var monthS = start.getMonth();
Doc I found but coudnt' understand -> https://fullcalendar.io/docs/view-object
I create this quesiton because I saw that the question here on SO refer to getView old Method.
calendar.js
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
/*some customization of fullcalendar*/
dateClick: function(event, date) {
/*code*/
},
eventClick: function(event){
/*code*/
});
calendar.render();
document.getElementById("test").onclick = function() {exportTableToExcel()};
function exportTableToExcel(){
var username = '<?php echo $_SESSION["nome"]; ?>';
var view = calendar.view;
var start = view.currentStart;
const month = start.toLocaleString('default', { month: 'long' });
var year = new Date(start).getFullYear();
var tab_text = '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
tab_text = tab_text + '<head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>';
tab_text = tab_text + '<x:Name>Ore_'+month+'_'+year+'_'+username+'</x:Name>';
tab_text = tab_text + '<x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet>';
tab_text = tab_text + '</x:ExcelWorksheets></x:ExcelWorkbook></xml></head><body>';
tab_text = tab_text + "<table border='2px'>";
tab_text = tab_text + $('#table2').html();
tab_text = tab_text + '</table></body></html>';
var data_type = 'data:application/vnd.ms-excel';
$('#test').attr('href', data_type + ', ' + encodeURIComponent(tab_text));
$('#test').attr('download', 'Ore_'+month+'_'+year+'_'+username+'.xls');
};
});
Basically I'm having trouble on this last function exportTableToExcel() where I have
var view = calendar.view;
I also tried with
var view = $('#calendar').view
with no success
The upgrade from fullcalendar v03 to fullcalendar v06 to get the view is:
var view = $('#calendar').fullCalendar('getView');
to
var view = calendar.view;
You have to do it before rendering the calendar.
Related
I have a Google web app that I am creating and have hit a snag.
In this app I use multiple dropdowns. These dropdowns are pulling data from a spreadsheet using the below code.
var userList = ws.getRange(2,1,ws.getRange("A2").getDataRegion().getLastRow(),1).getValues();
var sourceList = ws.getRange(2,2,ws.getRange("B2").getDataRegion().getLastRow(),1).getValues();
Now, the problem I am running into is that every single dropdown I use is as long as the longest column in the spreadsheet I am pulling the values from. For example. If column A has 4 values and column B has 12 then the dropdown that pulls from column A will have the four values plus an additional 8 blank values.
How can I change up this code to get the last row of the column I'm pulling values from and not the last row of the longest column? I know I can just put a number value in place of ws.getRange("A2").getDataRegion().getLastRow() but I'll be adding new options to the dropdown regularly and would prefer not to have to update the code each time.
Here is the function where this needs to happen
function doGet(e){
var ss = SpreadsheetApp.openById(ssId)
var ws = ss.getSheetByName("List Source - External");
var range = ws.getRange("A2");
Logger.log(range.getNextDataCell(SpreadsheetApp.Direction.DOWN).getA1Notation());
var lastRowInColumnA = range.getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow();
var userList = ws.getRange(2,1,lastRowInColumnA-1,1).getValues();
var sourceList = ws.getRange(2,2,lastRowInColumnA-1,1).getValues();
//var userList = ws.getRange("A2:A").getValues();
//var userList = ws.getRange(2,1,ws.getRange("A2:A").getDataRegion().getLastRow(),1).getValues();
//var sourceList = ws.getRange(2,2,ws.getRange("B2").getDataRegion().getLastRow(),1).getValues();
var brandList = ws.getRange(2,3,lastRowInColumnA-1,1).getValues();
var brand2List = ws.getRange(2,3,ws.getRange("C2").getDataRegion().getLastRow(),1).getValues();
var userListArray = userList.map(function(r){ return '<option>' + r[0] + '</option>'; }).join('');
var sourceListArray = sourceList.map(function(r){ return '<option>' + r[0] + '</option>'; }).join('');
var brandListArray = brandList.map(function(r){ return '<option>' + r[0] + '</option>'; }).join('');
var brand2ListArray = brand2List.map(function(r){ return '<option>' + r[0] + '</option>'; }).join('');
var tmp = HtmlService.createTemplateFromFile("builder");
tmp.userList = userListArray;
tmp.sourceList = sourceListArray;
tmp.brandList = brandListArray;
tmp.brand2List = brand2ListArray;
return tmp.evaluate();
}
This can be achieved with getNextDataCell(direction)
This method gives you the last not empty cell of an adjacent data range in the specified direction.
Sample:
...
var range = ws.getRange("A2");
Logger.log(range.getNextDataCell(SpreadsheetApp.Direction.DOWN).getA1Notation());
var lastRowInColumnA = range.getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow();
var userList = ws.getRange(2,1,lastRowInColumnA-1,1).getValues();
var sourceList = ws.getRange(2,2,lastRowInColumnA-1,1).getValues();
...
UPDATE
Here is a sample how you can find the last row of each column individually within a loop:
function doGet(e){
var ss = SpreadsheetApp.openById(ssId)
var ws = ss.getSheetByName("List Source - External");
var range = ws.getRange("A2:D2");
var valuesArray = [];
for (var i = 1; i <= range.getLastColumn(); i++){
var lastRowInColumn = range.getCell(1, i).getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow();
var list = ws.getRange(2,i,lastRowInColumn-1,1).getValues();
valuesArray.push(list);
}
var userListArray = valuesArray[0].map(function(r){ return '<option>' + r[0] + '</option>'; }).join('');
var sourceListArray = valuesArray[1].map(function(r){ return '<option>' + r[0] + '</option>'; }).join('');
var brandListArray = valuesArray[2].map(function(r){ return '<option>' + r[0] + '</option>'; }).join('');
var brand2ListArray = valuesArray[3].map(function(r){ return '<option>' + r[0] + '</option>'; }).join('');
var tmp = HtmlService.createTemplateFromFile("builder");
tmp.userList = userListArray;
tmp.sourceList = sourceListArray;
tmp.brandList = brandListArray;
tmp.brand2List = brand2ListArray;
return tmp.evaluate();
}
I am very new to this, so please bear with me. I am trying to get my code to look at each cell in a column, then compare that date to the current date, and if they match send an email. I am aware I will need a loop of some sort to get it to look through the column, but I haven't even gotten that far. I've tried every method I can find online to just get it to compare one cell to the date and send the email.
I tested the email function prior to adjusting it to compare the date, so I know that is working. Put something definitely isn't working...
function sendEmail() {
//Fetch the date
var removalDateRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expirations").getRange("E2");
var removalDate = removalDateRange.getValue();
var currentDateRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Alerts").getRange("C2");
var currentDate = new Date();
var ui = SpreadsheetApp.getUi();
//Check Date
if (removalDate == currentDate) {
//Fetch the email address
var emailRange =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Alerts").getRange("B2");
var emailAddress = emailRange.getValue();
//Fetch Item Brand
var itemBrandRange =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expirations").getRange("B2");
var itemBrand = itemBrandRange.getValue();
//Fetch Item Name
var itemNameRange =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expirations").getRange("A2");
var itemName = itemNameRange.getValue();
//Fetch Item Location
var itemLocationRange =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expirations").getRange("H2");
var itemLocation = itemLocationRange.getValue();
// Send Alert Email
var message = 'The ' + itemBrand + ' ' + itemName + ' in ' + itemLocation + ' will expire in 2 months. Please use and replace item.';
// Second Column
var subject = 'Pantry Alert';
MailApp.sendEmail(emailAddress, subject, message);
}
}
EDIT
Okay, I had it working late last night and even got it to loop through, and somehow I've broken it again. I've been looking at answers for hours trying to adjust things to make it work. What am I doing wrong?
function emailAlert() {
// today's date information
var today = new Date();
var todayMonth = today.getMonth() + 1;
var todayDay = today.getDate();
var todayYear = today.getFullYear();
// 2 months from now
var oneMonthFromToday = new Date(todayYear, todayMonth, todayDay);
var oneMonthMonth = oneMonthFromToday.getMonth() + 2;
var oneMonthDay = oneMonthFromToday.getDate();
var oneMonthYear = oneMonthFromToday.getYear();
// getting data from spreadsheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Exp");
var startRow = 2; // First row of data to process
var numRows = 500; // Number of rows to process
var dataRange = sheet.getRange(startRow, 1, numRows, 999);
var data = dataRange.getValues();
//looping through all of the rows
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var expireDateFormat = Utilities.formatDate(new Date(row[5]),
'ET',
'MM/dd/yyyy'
);
//email Information
var subject = 'Pantry Item Needs Attention!';
var message1 =
row[6] + ' ' + row[3] + ' of ' + row[2] + ' ' + row[1] + ' will expire on ' + expireDateFormat + '. Item can be found in ' + row[7]
+ '. Please Remove and Replace Item.' +
'\n' + 'Thanks Steve!';
var message2 =
row[6] + ' ' + row[3] + ' of ' + row[2] + ' ' + row[1] + ' will expire on ' + expireDateFormat + '. Item can be found in ' + row[7] +
'. Please ensure item has been replaced, removed from the pantry, and deleted from inventory.' +
'\n' + 'Thanks Steve!'
//expiration date information
var expireDateMonth = new Date(row[5]).getMonth() + 1;
var expireDateDay = new Date(row[5]).getDate();
var expireDateYear = new Date(row[5]).getYear();
//checking for today
if (
expireDateMonth === todayMonth &&
expireDateDay === todayDay &&
expireDateYear === todayYear
) {
ui.alert(message1);
}
}
}
Dates can be frustrating to work with, so consider doing the whole thing (loop, if then statement...) with an integer first and then returning to the date part if you're having trouble. That said, try adjusting the top of your code to look like the following:
var ss =SpreadsheetApp.getActiveSpreadsheet();
var removalDateVal = ss.getSheetByName("Expirations").getRange("E2").getValue();
var removalDate = new Date(removalDateVal);
var currentDateVal = ss.getSheetByName("Alerts").getRange("C2").getValue();
var currentDate = new Date(currentDateVal);
That will give you two date objects. But BEWARE! These dates contain time as well as calendar date so they may not equal each other even when they appear to. Use setHours() to zero out the date as seen below.
currentDate.setHours(0,0,0);
removalDate.setHours(0,0,0);
Other notes, it's best practice to set a variable for a spreadsheet and worksheet as shown by Google here. It makes the code much more readable.
I have searched but cannot find any examples
What I am sending is
//Send Email
var emailContents =
{
to: techManagerEmail+","+organiserEmail,
subject: "New Technical Support Request for " + eventName,
body: "Event Name: "+eventName+ "\n\n"+"Event Room: "+eventRoom+ "\n\n"+eventDescription +"\n\n"+ allEvents + "\n\n" + "Google Folder: "+newFolderLink+"\n \n"+techTeam+" Calendar Link: "+ calendarLink + "\n\n" + "Date Submitted: " + submitionDate + " by: " + submitterEmail,
};
MailApp.sendEmail(emailContents);
}
When I send, it sends as the user that created the form (me) when I want the person filling the form to be the sender - (I would also like the person filling the form to be the creator of the calendar event, but I think that may be a larger issue). It would also be nice to be able to change the display name.
I have looked at the api sendAs options but am struggling to work out how to use it or the syntax.
Any advice would be appreciated.
As requested, full code:
function onSubmit(e)
{
//Set General Variables
var formResponses = e.response.getItemResponses();
var submitterEmail = e.response.getRespondentEmail();
var submitionDate = e.response.getTimestamp();
var eventName = formResponses[0].getResponse();
var eventDescription = formResponses[1].getResponse();
var moduleCode = formResponses[2].getResponse();
var noStudents = formResponses[3].getResponse();
var organiser = formResponses[4].getResponse();
var organiserEmail = formResponses[5].getResponse();
var eventRoom = formResponses[6].getResponse();
var techTeam = formResponses[7].getResponse();
var supportRequired = formResponses[8].getResponse();
var supportDescription = formResponses[9].getResponse();
var equipmentRequired = formResponses[10].getResponse();
var startDate = formResponses[11].getResponse();
var nextAction = formResponses[18].getResponse();
var supportDateNo = 11;
var supportStartNo = 12;
var eventStartNo = 13;
var eventEndNo = 14;
var supportEndNo = 15;
var eventDaysDataNo = 16;
var eventEndDateNo = 17;
var nextActionNo = 18;
var nextActionSwitch = 1;
var loopNo = 1;
var calendarId = CalendarApp.getCalendarById(calId);
var allEvents ="";
var day = 1000*60*60*24
var eventDescription = 'Organiser: ' + organiser + '\n \n' +
'Module Code: ' + moduleCode + '\n \n' +
'Description of the Event: ' + eventDescription + '\n \n' +
'Type of support: ' + supportRequired + '\n \n' +
'Description of Support: ' + supportDescription + '\n \n'+
'Number of Students: ' + noStudents + '\n \n'+
'Equipment Required: ' + equipmentRequired + '\n\n';
//General Operations
if(organiserEmail==""){var organiserEmail = submitterEmail};
if(techTeam=="Performance Studios")
{
var calId = "****";
var techManagerEmail = "****";
var calendarLink = "****";
var parentFolder = DriveApp.getFolderById('****');
};
if(techTeam=="****")
{
var calId = "****";
var techManagerEmail = "****";
var calendarLink = "****";
var parentFolder = DriveApp.getFolderById('****');
};
if(techTeam=="****")
{
var calId = "****";
var techManagerEmail = "****";
var calendarLink = "****";
var parentFolder = DriveApp.getFolderById('****');
};
if(techTeam=="****")
{
var calId = "****";
var techManagerEmail = "****";
var calendarLink = "****";
var parentFolder = DriveApp.getFolderById('****');
};
//create attachments
var folderName = startDate + ' ' + eventName
var newFolder = parentFolder.createFolder(folderName).getId();
var newFolderLink = DriveApp.getFolderById(newFolder).getUrl();
//Calendar Creation Loop
while(nextActionSwitch==1)
{
//Set Variables
var supportDate = formResponses[supportDateNo].getResponse();
var supportStart = formResponses[supportStartNo].getResponse();
var eventStart = formResponses[eventStartNo].getResponse();
var eventEnd = formResponses[eventEndNo].getResponse();
var supportEnd = formResponses[supportEndNo].getResponse();
var eventDaysData = formResponses[eventDaysDataNo].getResponse();
var eventEndDate = formResponses[eventEndDateNo].getResponse();
var nextAction = formResponses[nextActionNo].getResponse();
var indivudualTechDetails = "";
var individualEventDetails = "";
var individualRepeatDetails = "";
//Time Operations
var eventEndDate = eventEndDate.replace(/-/g, "");
if (eventDaysData == "All"){var eventDaysData = "MO,TU,WE,TH,FR,SA,SU,"};
if (eventDaysData =="No Repeat"){var eventDaysData = ""; var eventEndDate = ""};
if (eventEndDate == ""){var eventDaysData = ""};
var alteredEndDate = Number(eventEndDate)+1;
var startDateTime = new Date(supportDate+"T"+supportStart+":00");
var endDateTime = new Date(supportDate+"T"+supportEnd+":00.000Z");
if (endDateTime<=startDateTime){var endDateTime = new Date(endDateTime.getTime() + day)};
var start = Utilities.formatDate(startDateTime, "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
var end = Utilities.formatDate(endDateTime, "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
var finalDescription = eventDescription;
if (eventStart!=""){var finalDescription = eventName + ' Start Time: ' + eventStart +'\n' + eventName + ' End Time: ' + eventEnd + '\n \n' + eventDescription};
//Date Display Operations
var eventDay = startDateTime.getDate();
var eventMonth = startDateTime.getMonth()+1;
var eventYear = startDateTime.getFullYear();
var eventEmailDate = eventDay+"/"+eventMonth+"/"+eventYear;
var repeatEndDate = new Date(eventEndDate+"T"+supportStart+":000Z");
var eventEndDay = repeatEndDate.getDate();
var eventEndMonth = repeatEndDate.getMonth()+1;
var eventEndYear = repeatEndDate.getFullYear();
var eventEmailEndDate = eventEndDay+"/"+eventEndMonth+"/"+eventEndYear;
//Create Event
var event =
{
summary: eventName,
location: eventRoom,
start: {dateTime: start, timeZone: "GMT"},
end: {dateTime: end, timeZone: "GMT"},
description: finalDescription,
colorId: 8,
attendees: [{email: submitterEmail}, {email:organiserEmail}],
attachments: [{fileId: newFolder, fileUrl:newFolderLink, title: eventName+" Folder"}],
"recurrence": ["RRULE:FREQ=DAILY;UNTIL="+alteredEndDate+";BYDAY="+eventDaysData]
};
if (eventEndDate == ""|| eventDaysData == "No Repeat")
{
var event =
{
summary: eventName,
location: eventRoom,
start: {dateTime: start, timeZone: "GMT"},
end: {dateTime: end, timeZone: "GMT"},
description: finalDescription,
colorId: 8,
attendees: [{email: submitterEmail}, {email:organiserEmail}],
attachments: [{fileId: newFolder, fileUrl:newFolderLink, title: eventName+" Folder"}],
};
};
var eventLink = Calendar.Events.insert(event, calId, {SendNotifications: true, supportsAttachments:true}).getHtmlLink();
//Event Details
var individualTechDetails =
"Instance: " + loopNo + "\n\n" +
"Start Date: " + eventEmailDate + "\n\n" +
"Tech Start Time: " + supportStart + "\n\n" +
"Tech End Time: " + supportEnd + "\n\n";
if (eventStart != ""){var individualEventDetails =
"Event Start Time: " + eventStart + "\n\n" +
"Event End Time: " + eventEnd + "\n\n"};
if (eventEndDate != ""){ var individualRepeatDetails =
"Repeats: " + eventDaysData + "\n\n"+
"End Date: " + eventEndDate+"\n\n"};
var combinedEventDetails = individualTechDetails + individualEventDetails + individualRepeatDetails + "Event Link: "+ eventLink;
var allEvents = allEvents + combinedEventDetails + "\n\n -- \n \n";
//Set Loop Values
var nextActionSwitch = 0;
if (nextAction=="Add dates with a different pattern")
{
var nextActionSwitch = 1;
var loopNo = loopNo +1;
var supportDateNo = supportDateNo +8;
var supportStartNo = supportStartNo +8;
var eventStartNo = eventStartNo +8;
var eventEndNo = eventEndNo +8;
var supportEndNo = supportEndNo +8;
var eventDaysDataNo = eventDaysDataNo +8;
var eventEndDateNo = eventEndDateNo +8;
var nextActionNo = nextActionNo +8;
};
};
//Send Email
var requestorEmails = submitterEmail + ", " + organiserEmail;
if (organiserEmail == submitterEmail){requestorEmails = organiserEmail};
var emailContents =
{
to: techManagerEmail+","+requestorEmails,
subject: "New Technical Support Request for " + eventName,
body: "Event Name: "+eventName+ "\n\n"+"Event Room: "+eventRoom+ "\n\n"+eventDescription +"\n\n"+ allEvents + "\n\n" + "Google Folder: "+newFolderLink+"\n \n"+techTeam+" Calendar Link: "+ calendarLink + "\n\n" + "To create another event: ****" + "\n\n" + "Date Submitted: " + submitionDate + " by: " + submitterEmail,
name: techTeam + " Technical Support Requests",
};
MailApp.sendEmail(emailContents);
}
There are limited ways you can achieve this. The only way to achieve that is by logging with the account of the person filling the form. If you're running the script automatically via a trigger, just set the trigger with this account.
There's an open issue about this on Apps Script tracker:
Issue Tracker
Hope this answers your question!!
Let me first express that programming is not my speciality so I will do my best to explain what I'm working on. At my employer, we have a company activity calendar on a free Gmail account and then we have separate accounts through Google Apps (paid) for each employee. I'm working on a script that pulls the events from said calendar, adds them to an agenda-styled email, and then sends the email to the Google Apps accounts. Our goal is to allow the employee to open the email, click an event he/she is interested in, and then RSVP to the event. It might be worth noting, the script is saved/running under the free account.
We have most of the code working but the RSVP feature is not appearing when the event is opened. We are making sure that the Google App account is logged in when the agenda email is viewed and that the account is an invited guest to the event. I suspect this is due to some type of authentication issue in the way we are generating the eventURL. I also believe this isn't working because the script is running as the "user" who already owns the calendar. If these two suspicions are true, I'm not sure how to fix it.
Here is the code for your review. I've removed the HTML formatting and our private calendar addresses.
function ordinal_suffix_of(i) {
var j = i % 10,
k = i % 100;
if (j == 1 && k != 11) {
return i + "st";
}
if (j == 2 && k != 12) {
return i + "nd";
}
if (j == 3 && k != 13) {
return i + "rd";
}
return i + "th";
}
function myFunction() {
var calendar = CalendarApp.getCalendarById('HIDDEN#group.calendar.google.com');
var now = new Date();
var oneWeekFromNow = new Date(now.getTime() + 604800000);
var twoWeeksFromNow = new Date(now.getTime() + 1209600000);
var threeWeeksFromNow = new Date(now.getTime() + 1814400000);
var eventsOneWeek = calendar.getEvents(now, oneWeekFromNow);
var eventsTwoWeeks = calendar.getEvents(oneWeekFromNow, twoWeeksFromNow);
var eventsThreeWeeks = calendar.getEvents(twoWeeksFromNow, threeWeeksFromNow);
var body = '';
for (i = 0; i < eventsOneWeek.length; i++) {
var day = ordinal_suffix_of(Utilities.formatDate(eventsOneWeek[i].getStartTime(), "GMT-0400", "d"));
var splitEventId = eventsOneWeek[i].getId().split('#');
var eventURL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + "HIDDEN#group.calendar.google.com");
var eventTitle = eventsOneWeek[i].getTitle();
var eventStart = Utilities.formatDate(eventsOneWeek[i].getStartTime(), "GMT-0400", "MMMMM");
eventStart += ' ' + day;
eventStart += Utilities.formatDate(eventsOneWeek[i].getStartTime(), "GMT-0400", " 'at' hh:mm a");
body += '';
}
for (i = 0; i < eventsTwoWeeks.length; i++) {
var day = ordinal_suffix_of(Utilities.formatDate(eventsTwoWeeks[i].getStartTime(), "GMT-0400", "d"));
var splitEventId = eventsTwoWeeks[i].getId().split('#');
var eventURL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + "HIDDEN#group.calendar.google.com");
var eventTitle = eventsTwoWeeks[i].getTitle();
var eventStart = Utilities.formatDate(eventsTwoWeeks[i].getStartTime(), "GMT-0400", "MMMMM");
eventStart += ' ' + day;
eventStart += Utilities.formatDate(eventsTwoWeeks[i].getStartTime(), "GMT-0400", " 'at' hh:mm a");
body += '';
}
for (i = 0; i < eventsThreeWeeks.length; i++) {
var day = ordinal_suffix_of(Utilities.formatDate(eventsThreeWeeks[i].getStartTime(), "GMT-0400", "d"));
var splitEventId = eventsThreeWeeks[i].getId().split('#');
var eventURL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + "HIDDEN#group.calendar.google.com");
var eventTitle = eventsThreeWeeks[i].getTitle();
var eventStart = Utilities.formatDate(eventsThreeWeeks[i].getStartTime(), "GMT-0400", "MMMMM");
eventStart += ' ' + day;
eventStart += Utilities.formatDate(eventsThreeWeeks[i].getStartTime(), "GMT-0400", " 'at' hh:mm a");
body += '';
}
GmailApp.sendEmail('HIDDEN#email.com', 'Testing Calendar Agenda', body,{'htmlBody':body});
}
Thank you in advance for any insight/help you can share! We greatly appreciate it!
Edit:
I copied the script over to my Google Apps account and adjusted the code to pull from my default calendar instead. I then created a new event on my calendar and invited my colleague to it. When I run the script and open the event, it displays an option to change my RSVP. When my colleague opens the same link, it displays the exact same option to change my RSVP status and nothing for his RSVP. This confirms that it's not isolated to the calendar or account and is specific to the link and how it's generated.
I am getting this extremely frustrating error. I am in no way creating or deleting too many calendars - at most I've created about 20 and my script is trying to create just one!
I've narrowed down the problem to event.addGuests(). When I remove this line, the event gets added. When I keep it, this is where Google reports the error to be.
I've tried adding
Utilities.sleep(5000);
before event.addGuest() to see if slowing the script down would work, but this doesn't work either.
Here is the whole script. Note, there is only one item in the spreadsheet now
var ACCEPTED = "ACCEPTED";
var PUBLISHED = "PUBLISHED"
var NOT_PUBLISHED = "NOT_PUBLISHED";
function createCalendarEventsFromSheets(){
// Get Calendar Info
var calId = "privatecalendar#group.calendar.google.com";// use default claendar for tests
var cal = CalendarApp.getCalendarById(calId);
// Get Google Sheet Info
var ss = SpreadsheetApp.openById('privatespreadhseet');
var sheet = ss.getSheets()[0];
var range = sheet.getDataRange();
var rows = range.getValues();
Logger.log("Rows found: " + rows.length);
// Iterate through Google Sheets rows and create events
for (i = 1; i < rows.length; i++){
var row = rows[i];
// Gather variables for row
var eventTitle = row[1];
var date = new Date(row[2]);
var location = row[3];
var shiftStart = row[4];
var shiftEnd = row[5];
var eventStart = row[6];
var eventEnd = row[7];
var numberOfKeys = row[8];
var role = row[9];
var notes = row[10];
var accepted = row[13];
var alreadyPublished = row[14]
// If event has been accepted and wasn't published yet, create event
Logger.log("accepted: " + accepted + ", alreadyPublished " + alreadyPublished);
if (accepted == ACCEPTED && alreadyPublished != PUBLISHED){
Logger.log("**** TRUE ****");
// Set up calendar event
var cal_start = new Date(date.getYear(), date.getMonth(), date.getDate(), shiftStart.getHours(), shiftStart.getMinutes());
Logger.log("cal_start: " + cal_start);
var cal_end = new Date(date.getYear(), date.getMonth(), date.getDate(), shiftEnd.getHours(), shiftEnd.getMinutes());
Logger.log("cal_end: " + cal_end);
var description = "Keys Required: " + numberOfKeys + "\n\nRole: " + role + "\n\nEvent Start Time: " + eventStart.getHours() + ":" + eventStart.getMinutes() + ", Event End Time: " + eventEnd.getHours() + ":" + eventEnd.getMinutes() + "\n\nNotes:\n" + notes;
// CREATE EVENT
var event = cal.createEvent(eventTitle, cal_start, cal_end);
event.setDescription(description);
event.setLocation(location);
//Utilities.sleep(5000); // I've tried this, to no avail
event.addGuest("rap#gmail.com"); //error message details point to here
event.addGuest('e.leg#gmail.com');
event.addGuest('ba#hotmail.com');
event.addGuest('r#hotmail.com');
event.addGuest('js#gmail.com');
event.addGuest('w#gmail.com');
event.addGuest('no.abe#gmail.com');
event.addGuest('esth#gmail.com');
event.addGuest('carolin#gmail.com');
event.addGuest('kalan#gmail.com');
event.addGuest('bob#gmail.com');
event.addGuest('rob#gmail.com');
sheet.getRange(i+1, 15).setValue(PUBLISHED);
Logger.log("Event created, starting at: " + event.getStartTime());
}
}
}