I am new here, and somehow new for js for Google Scripts.
I have created a form, which fills a sheet, and want that a Calendar would be update with the data from the sheet. This form and calendar will be shared with a large group, so we all can create Events in a particular format, and to avoid deleting or modifying Events that should not be modified.
When I run the script from the workspace it runs properly, but after defining the trigger to run it, the date format changes (I believe that this is the reason, but I am not sure) and all Events are created for 1969. Below I present part of the script.
So, again, the script runs fine when I start it from the working space, but it changes the date format when running by trigger (onsubmit).
I have already removed and recreated the trigger, but it didn't work.
The date format is set as dd/MM/yyyy, and the time as HH:mm:ss.
Does anybody know how to fix this issue?
Thanks in advance
Best regards
function create_event_PRH(){\
var calId = ID from Calendar;\
var calendar = CalendarApp.getCalendarById(calId);\
var timezone=calendar.getTimeZone();
// Getting data from the spreadsheet\
var ss = SpreadsheetApp.getActive();\
var ss_name = ss.getName();\
var sheet = ss.getActiveSheet();\
var range = sheet.getDataRange();\
var values = range.getValues();\
var lastRow = sheet.getLastRow()-1;
// Definition of the starting and finishing time in the spreadsheet (I am using this part of the script to sum date and time of the day)\
var range = sheet.getRange('P'+String(lastRow+1)).setFormula('H'+String(lastRow+1)+'+I'+String(lastRow+1));\
var range = sheet.getRange('Q'+String(lastRow+1)).setFormula('H'+String(lastRow+1)+'+J'+String(lastRow+1));\
Logger.log(Utilities.formatDate(new Date(), timezone, 'dd/MM/yyyy HH:mm:ss'));
// Start and end time
var event_values = values[lastRow];\
var event_start_time=new Date(event_values[15]);\
var event_end_time=new Date(event_values[16]);
// Event description and creation\
var lecture_title=event_values[5];\
var program_number=event_values[2];\
var event_title = 'Program'+program_number+' - '+lecture_title;\
var description='Presenter: '+event_values[10]+'\nInstitution:'+event_values[11];\
var event = calendar.createEvent(event_title,event_start_time,event_end_time);\
event = event.setDescription(description);\
}