Google Apps Script, Propagate comma separated list from google forms list .onlyOnWeekdays() as variable calls -
i have form creating days of week event may occur on (mon, tue, wed etc) - output gives days of week, comma separated in single cell on spreadsheet.
i have called cell apps script. need put contents of list in .onlyonweekdays google calendar entry being created occurs on appropriate weekdays.
every time try put list in remotely, cannot convert array weekday[].
here code
function export_techs_to_calendar() { var sheet = spreadsheetapp.getactivesheet(); var startrow = 2; // first row of data process var numrows = 500; // number of rows process var datarange = sheet.getrange(startrow, 1, numrows, 24); var data = datarange.getvalues(); var cal = calendarapp.getcalendarsbyname("- performance venue staffing")[0]; var startdateandtime = 'sat aug 01 2016 00:00:00 gmt+0100 (bst)'; var enddateandtime = 'wed aug 31 2017 23:59:59 gmt+0100 (bst)'; var events = cal.getevents(new date(startdateandtime), new date(enddateandtime)); var mon = calendarapp.weekday.monday; var tue = calendarapp.weekday.tuesday; var wed = calendarapp.weekday.wednesday; var thur = calendarapp.weekday.thursday; var fri = calendarapp.weekday.friday; var sat = calendarapp.weekday.saturday; var sun = calendarapp.weekday.sunday; //delete calendar events (var i=0; i<events.length ;i++){ events[i].deleteevent(); utilities.sleep(200); } //export calendar events day (i in data) { var row = data[i]; var sdate = row[2]; var fdate = row[4]; var ndays = ((fdate - sdate)/(1000*60*60*24)); var days = row[22]; var repeat = calendarapp.newrecurrence().addweeklyrule().onlyonweekdays([days]).until(new date(fdate)); var title = row[10]+" - "+row[6]; var cancel = row[19]; var des = "description: "+row[7]+"\n"+"organiser: "+row[8]+"\n"+"course: "+row[9]+"\n"+"number of staff: "+row[11]+"\n"+"staff assigned: "+row[13]; if (title == ""){ title = 0}; {}; var loc = row[10]; var gue = row[8]+", "+row[12]; if (gue == "-"){gue = ""}; //multi-day event if (((typeof title == 'string') && (sdate != "") && (cancel == "") && (ndays > 1))){ try{ cal.createalldayeventseries(title, new date(sdate), repeat, {location:loc, description:des, guests:gue, sendinvites:true}); utilities.sleep(200); } catch (e) { cal.createalldayeventseries(title, new date(sdate), repeat, {location:loc, description:des}); utilities.sleep(200); }; }; {}; }
any appreciated.
in code:
var days = row[22];
will returning single string
"mon,tue,wed"
you need split string array of individual values:
var days = row[22]; var daysarray = days.split(",");
which give you
["mon", "tue", "wed"]
now, daysarray
may enough pass in argument in .onlyonweekdays()
method.
if isn't you'll need 'build' argument looping through daysarray
, pushing calendarapp.weekday.weekday
syntax values array , use instead.
edit
for i'd use object:
var weekdaysyntax = { mon : "calendarapp.weekday.monday", tue : "calendarapp.weekday.tuesday", wed : "calendarapp.weekday.wednesday", thu : "calendarapp.weekday.thursday", fri : "calendarapp.weekday.friday", } var output = []; //assumes daysarray = ["mon", tue", "wed"]; (i in daysarray) { var day = daysarray[i]; output.push(weekdaysyntax[day]); }; console.log(output);//should return ["calendarapp.weekday.monday", "calendarapp.weekday.tuesday", "calendarapp.weekday.wednesday"]
this assumes daysarray contains values ["mon","tue","wed"]? you've not explicitly shown values you're working adjust necessary :)
additional issue calendarapp.newrecurrence().addweeklyrule().onlyonweekdays()
method doesn't accept array of strings argument? let me know how on :)
Comments
Post a Comment