Google脚本将表单提交到日历活动 [英] Google Script to Submit Form to Calendar Event

查看:119
本文介绍了Google脚本将表单提交到日历活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



试图让孩子们尽可能快速和轻松地学习(使用我的个人Google帐户创建表格并将日历发布到我的课程网站)无法访问Google Apps)使用此表单安排补考测试



一个快速和肮脏的胜利将是他们的表单提交添加到我的日历作为一个全天事件与描述字段中的细节。然后,我可以查看和编辑活动的具体时间要求(我只有一些时间选项在表格上提供的下拉选择项目。)



一个美丽的而优雅的解决方案是让脚本在下拉列表中指定的日期和时间写下事件,但我认为这需要法术......



表单将其对电子表格的回复写入罚款和电子邮件通知也起作用,但无法使日历事件创建发生。



将继续尝试查找/学习必要的代码,但将非常感激一个正确的方向踢。



干杯,

解决方案这是一个魔法礼物,因为你是一位老师(我也是),而不是程序员(我也不是),希望能够完全满足你的需求。



编辑:我在描述中添加了提交日期/时间

  function createCalEvent e){
Logger.log(E);
//这将返回如下所示的内容:
/ *
{values = [11/9/2014 22:30:00,serge,test descr,11/7/2014,Before学校| 7:30],
namedValues = {你的全名= [serge],正在努力弥补= [测试descr],你将弥补作品的日期= [11/7/2014],
化妆时间= [上学前| 7:30],Timestamp = [11/9/2014 22:30:00]},范围= Range,source =电子表格,authMode = FULL}
* /
var cal = CalendarApp.getCalendarById h22nevo15tm0nojb6ul4hu7ft8@group.calendar.google.com); //用正确的日历ID替换,这个用于测试(并且是公共的)
var name = e.namedValues [Your Full Name] [ 0];
var descr = e.namedValues [Make to Make] [0];
var submitTime = e.namedValues [Timestamp] [0];
var date = e.namedValues [您将创作作品的日期] [0] .split('/');
var time = e.namedValues [Makeup Time] [0] .split('|')[1] .split(':');
Logger.log(name +''+ descr +''+ date +''+ time); //这将返回serge test descr 11,7,2014 7,30
var startTime = new Date(date [2],date [0] -1,date [1]);
startTime.setHours(time [0],time [1],0,0);
endTime = new Date(startTime.getTime()+ 3600000); //假设事件为1小时
Logger.log('start ='+ startTime +'end ='+ endTime);
cal.createEvent('name ='+ name,startTime,endTime,{'description':descr +'(subimitted on'+ submitTime +')'});

您必须设置一个触发器(在表单提交上)当提交表单时触发该功能



重要提示:不要在没有脚本编辑器的情况下尝试使用此代码发送表单,它不会工作! (显然,e将是未定义的)

School teacher using my personal Google account to create forms and publish calendars to my class web site.

Trying to make it fast and easy as possible for kids (with no access to Google Apps) to schedule make up tests using this form.

A quick and dirty victory would be to have their form submission added to my calendar as an all-day event with the details in the description field. I could then review and edit the event to the specific time requested (I have only certain time options offered on the form as a drop-down selection item.)

A beautiful and elegant solution would be to have the script write the event on the day and time indicated on the drop-down, but I think that would require sorcery....

The form writes its responses to the spreadsheet fine and email notification works too, but can't get the calendar event creation to happen.

Will keep trying to find/learn the necessary code but would greatly appreciate a kick in the right direction.

Cheers,

解决方案

Here is a "sorcery gift" since you're a teacher (so am I) and not a programmer (neither am I) that hopefully does exactly what you need.

EDIT : I added the submission date/time in description

function createCalEvent(e) {
  Logger.log(e);
  // this will return something like this :
  /*
  {values=[11/9/2014 22:30:00, serge, test descr, 11/7/2014, Before school | 7:30], 
  namedValues={Your Full Name=[serge], Work to Make Up=[test descr], Date You Will Make Up Assignment=[11/7/2014], 
  Makeup Time=[Before school | 7:30], Timestamp=[11/9/2014 22:30:00]}, range=Range, source=Spreadsheet, authMode=FULL}
  */
  var cal = CalendarApp.getCalendarById("h22nevo15tm0nojb6ul4hu7ft8@group.calendar.google.com");// replace with the right calendar ID, this one is for test (and is public)
  var name = e.namedValues["Your Full Name"][0];
  var descr = e.namedValues["Work to Make Up"][0];
  var submitTime = e.namedValues["Timestamp"][0];
  var date = e.namedValues["Date You Will Make Up Assignment"][0].split('/');
  var time = e.namedValues["Makeup Time"][0].split('|')[1].split(':');
  Logger.log(name+' '+descr+' '+date+' '+time); // this will return  serge test descr 11,7,2014  7,30
  var startTime = new Date(date[2],date[0]-1,date[1]);
  startTime.setHours(time[0],time[1],0,0);
  endTime = new Date(startTime.getTime()+3600000); //assuming event is 1 hour long
  Logger.log('start='+startTime+'  end='+endTime);
  cal.createEvent('name = '+name, startTime, endTime, {'description':descr+' (subimitted on '+submitTime+')'});
}

You will have to set up a trigger (on form submit) to trigger that function when a form is submitted.

IMPORTANT NOTE : don't try this code from the script editor without sending a form, it won't work !!! (e will be undefined, obviously)

这篇关于Google脚本将表单提交到日历活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆