Google脚本:连接表单响应

时间:2017-08-08 10:28:44

标签: google-apps-script

我对谷歌脚本语言完全陌生。我一直在按照教程(http://www.jessespevack.com/blog/2016/2/9/turn-a-google-form-response-into-a-calendar-event)尝试将休假表单响应转换为日历事件。我试图找到一种方法将一些字段连接成一个属性,但我还没有找到实现这一目标的方法。

本教程包括以下部分:

var result = string.Join(",", classes.Split(',').Select(s => new {s, i =  IntPrefix(s)}).OrderBy(si => si.i).ThenBy(si => si.s).Select(si => si.s));

在每个属性(“eventTitle”,“startTime”等)之后,它要求我在引号之间列出我的表单中的字段名称(“名字”,“姓氏”)等。在每个中使用一个字段工作得很好,但我需要将两个字段连接成一些属性(例如“名字”+“姓氏”),但我知道的所有传统方法都不起作用。

组合问题(即单个名称字段)不是一个选项,因为我需要收集更多数据。

非常感谢任何帮助!

非常感谢!

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您需要在新活动中包含额外的表单项/字段。但是,由于createEvent()的参数有限 - 您希望将额外的表单信息合并到createEvent() parameters之一(例如,事件“描述”)中?

// Add the extra form fields into your form map
formMap : {
  eventTitle : "",
  startTime : "",
  endTime: "",
  firstName: "", //to be concatenated into description or other parameter
  lastName: "", //to be concatenated into description or other parameter
  description: "",
  location: "",
  email: "",
},


// Add the new form items/fields to the `switch` statement
function getFormResponse() {
  var firstName, lastName;
...

  for (var i = 0, x = itemResponses.length; i<x; i++) {

...

  switch (thisItem) {
    case GLOBAL.formMap.eventTitle:
      eventObject.title = thisResponse;
      break;
    case GLOBAL.formMap.startTime:
      eventObject.startTime = thisResponse;
      break;
    case GLOBAL.formMap.endTime:
      eventObject.endTime = thisResponse;
      break; 
    case GLOBAL.formMap.firstName:
      firstName = thisResponse;
      break;
    case GLOBAL.formMap.lastName:
      lastName = thisResponse;
      break;
    case GLOBAL.formMap.description:
      eventObject.description = thisResponse;
      break;
    case GLOBAL.formMap.phone:
      eventObject.phone = thisResponse;
      break;
    case GLOBAL.formMap.email:
      eventObject.email = thisResponse;
      break;
    } 
  }

  //Once form responses are assigned, concatenate multiple items to eventObject.description
  eventObject.description += " with " + firstName + " " + lastName;

  return eventObject;
}

使用Addition assignment将表单字段连接到createEvent() parameters之一:

//Once form responses are assigned, concatenate multiple items to eventObject.description
eventObject.description += " with " + firstName + " " + lastName;