预填充谷歌表格

时间:2013-11-28 11:17:45

标签: google-apps-script google-drive-api google-form

我想预先填写Google表单,以便预填充的某些字段是来自其他表单的回复。 我的意思是说,我发出一些表格的回复,并获得第三方验证的信息。这种预填充可能吗?

1 个答案:

答案 0 :(得分:0)

function sendForm(e) {  
  //Code to open second form and get the items of the form
  var form = FormApp.openById('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');   
  var items = form.getItems();
  var formItem = items[0].asTextItem();   
  var formResponse = form.createResponse();

  var count=0;

  var response = formItem.createResponse(e.namedValues["Name"].toString());     
  formResponse.withItemResponse(response);

  formItem = items[1].asTextItem();
  response = formItem.createResponse(e.namedValues["Email"].toString());        
  formResponse.withItemResponse(response);

  //Creates URL with pre-filled data
  var url = formResponse.toPrefilledUrl();

  //Mail the link to the people required.
}

此代码位于第一个表单的响应表中,每次表单提交操作发生时,必须添加一个触发器来调用此函数。