google apps script - How to get the date of the form submitter or the document in a published add-on -
in google apps script add-on simply send, try capture timestamp. timestamp (using e.response.gettimestamp().tostring();
) formatted est, timezone (the timezone of master script file).
what have either timezone of person submitting form, or timezone of form document add-on installed on.
if has cool trick information appreciated.
if assume user running add-on in same timezone form, getting user's time zone should sufficient.
the calendarapp has gettimezone() method return time zone of user's primary calendar.
template.timezone = calendarapp.gettimezone();
below quick forms add-on demo display time zone in dialog. time zone returned string, name of time zone listed joda.org. format used google apps script triggerbuilders, example:
// schedule trigger execute @ noon every day in us/pacific time zone scriptapp.newtrigger("myfunction") .timebased() .athour(12) .everydays(1) .intimezone("america/los_angeles") .create();
code.gs
/** * @onlycurrentdoc limits script accessing current form. */ var dialog_title = 'timezone probe'; /** * adds custom menu items show sidebar , dialog. * * @param {object} e event parameter simple onopen trigger. */ function onopen(e) { formapp.getui() .createaddonmenu() .additem('show dialog', 'showdialog') .addtoui(); } /** * runs when add-on installed; calls onopen() ensure menu creation , * other initializion work done immediately. * * @param {object} e event parameter simple oninstall trigger. */ function oninstall(e) { onopen(e); } /** * opens dialog. dialog structure described in dialog.html * project file. */ function showdialog() { var template = htmlservice.createtemplatefromfile('dialog'); template.timezone = calendarapp.gettimezone(); var ui = template .evaluate() .setwidth(350) .setheight(180) .setsandboxmode(htmlservice.sandboxmode.iframe); formapp.getui().showmodaldialog(ui, dialog_title); }
dialog.html
<!doctype html> <html> <head> <base target="_top"> </head> <body> <div> timezone is: <?!= timezone ?> </div> </body> </html>
Comments
Post a Comment