英文:
How to get google form data at onFormSubmit
问题
-
为什么onFormSubmit事件的事件数据中没有任何响应数据(即表单数据)?
-
还需要执行其他操作吗(例如安装其他触发器)?
-
为了正确的操作,我应该做什么?
(注意:这只是返回翻译好的部分,不包含问题的答案。)
英文:
I want to send some google form data to outside API using UrlFetchApp.fetch when the google form is submitted but there is no form data in event data.
-
My script is here
function onFormSubmit(e) { Logger.log(JSON.stringfy(e)) UrlFetchApp.fetch('https://api.server.com/result', { method: 'POST', headers: { 'Content-Type': 'application/json', }, payload: JSON.stringify({ answer1 : e.response.getItemResponses()[0].getResponse(), answer2 : e.response.getItemResponses()[1].getResponse() }), }) }
-
I add trigger to google form
-
When google form is submitted, the function, onFormSubmit is called correctly but e has no response data like below log.
{"authMode":"FULL","response":{},"source":{},"triggerUid":"16459009"}
My question is
-
Why the event of onFormSubmit doesn't have any response data(=form data)?
-
Is there something to do more (like install other trigger?)
-
What should I do for correct action?
答案1
得分: 0
以下是您要翻译的内容:
您的脚本容器绑定了Google表单,并且具有一个名为onFormSubmit
的触发器,您认为您的日志显示脚本未收集任何表单响应数据。
您的日志结果并不意味着未收集任何响应数据。
事件对象response
包含一个FormResponse
对象,代表用户对整个表单的响应。
要查看您的表单响应数据,请在您的“stringify”行之后添加以下内容:
let responses = e.response.getItemResponses();
for (i = 0; i<responses.length ; i++){
Logger.log(responses[i].getResponse())
}
UrlFetchApp.fetch - 负载
建议的修改
从
payload: JSON.stringify({
answer1 : e.response.getItemResponses()[0].getResponse(),
answer2 : e.response.getItemResponses()[1].getResponse()
}),
到
payload: answer1 : e.response.getItemResponses()[0].getResponse(),
answer2 : e.response.getItemResponses()[1].getResponse()
,
英文:
You have an onFormSubmit
trigger for a script container-bound to a Google Form and you think that your log shows that the script is not collecting any form response data.
Your log results do NOT mean that no response data was collected.
The Event Objects response
contains a FormResponse
object, representing the user's response to the form as a whole.
To see your form response data, add the following after your "stringify" line:
let responses = e.response.getItemResponses();
for (i = 0; i<responses.length ; i++){
Logger.log(responses[i].getResponse())
}
UrlFetchApp.fetch - PayLoad
Suggested modification
From
payload: JSON.stringify({
answer1 : e.response.getItemResponses()[0].getResponse(),
answer2 : e.response.getItemResponses()[1].getResponse()
}),
To
payload: answer1 : e.response.getItemResponses()[0].getResponse(),
answer2 : e.response.getItemResponses()[1].getResponse()
,
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论