Javascript 谷歌表单>;谷歌表单>;谷歌代码=电子邮件通知
我不确定我应该把这个贴在哪里。我希望这是正确的地方 我有一个谷歌表单,当表单填写完毕时,回复会自动输入到谷歌表单中。因为我是所有者,所以我设置了默认的Google通知,告诉我在填写Google表单时表单已经更改: 这个过程是:填写谷歌表单>更新谷歌工作表,回复来自表单>电子邮件通知到我的电子邮件地址 我已经将谷歌工作表分享给了我公司的另一位用户。他们对工作表具有编辑权限。我希望此用户在表单发生更改时也能收到通知 所以这个过程是:填写谷歌表单>更新谷歌表单,回复来自表单>电子邮件通知到我和其他用户的电子邮件地址 我在网上搜索过,因为这在谷歌应用程序中还不可能实现(它只通知所有者)。建议在我的Google工作表上创建自定义Google代码,如下所示:Javascript 谷歌表单>;谷歌表单>;谷歌代码=电子邮件通知,javascript,google-apps-script,google-code,Javascript,Google Apps Script,Google Code,我不确定我应该把这个贴在哪里。我希望这是正确的地方 我有一个谷歌表单,当表单填写完毕时,回复会自动输入到谷歌表单中。因为我是所有者,所以我设置了默认的Google通知,告诉我在填写Google表单时表单已经更改: 这个过程是:填写谷歌表单>更新谷歌工作表,回复来自表单>电子邮件通知到我的电子邮件地址 我已经将谷歌工作表分享给了我公司的另一位用户。他们对工作表具有编辑权限。我希望此用户在表单发生更改时也能收到通知 所以这个过程是:填写谷歌表单>更新谷歌表单,回复来自表单>电子邮件通知到我和其他用户
function myFunction() {
MailApp.sendEmail("myemailaddress@mybusiness.com","Notification - Change in Spreadsheet","Notification - There has been a change in the Spreadsheet. Please view the change here: (I've put the url of sheet here) ");
MailApp.sendEmail("theotheruser@mybusiness.com","Notification - Change in Spreadsheet","Notification - There has been a change in the Spreadsheet. Please view the change here: (I've put the url of sheet here) ");
}
当我从代码编辑器运行此代码时,它会向我和其他用户发送我想要的自定义Google代码通知电子邮件
当我填写表格时,回复会在表格中更新,我会收到来自谷歌官方变更通知的电子邮件通知。另一个用户和我没有收到定制的谷歌代码电子邮件通知
我已经在触发器部分查看了Google代码网站,但不确定如何编写这部分。
我想我需要在代码上写一个触发器,当工作表发生变化时运行自定义代码
因此,Google Form filled in>Google Sheet updated with responses from Form>change in Google Sheet会触发一个触发器>触发器运行自定义Google代码>其他用户,我会收到自定义Google代码电子邮件通知
有人可以帮助解决触发代码部分的问题,或者甚至可以推荐不同的解决方案吗
谢谢。您可以从脚本编辑器的“资源”->“当前项目的触发器”菜单项中添加触发器 然后按以下格式创建触发器:
电子表格中的“myFunction”->“On Change”对于触发器,我以前也编写过类似的代码,但这是针对事件onChange的。这里显然需要的是“OnFormsubmit”触发器。下面是我用带有内联注释的自定义菜单编写的代码
// Written by Madzihi
// on a nice Sunday afternoon
function onOpen(){ //Setting up all the custom menu components
var ss = SpreadsheetApp.getActiveSpreadsheet(); //Get the current active Spreadsheet
ss.addMenu('Custom Setup',[{name:'Select Sheet', //Assemble all the menu's component
functionName:'openSheet'},{name:'Set Trigger',functionName:'triggerSet'},
{name:'Delete Trigger',functionName:'delTrigger'}]);
ss.addEditor(Session.getActiveUser().getEmail()); //This line set up so editor(s) don't have to run manually the script to gain authorization
}
function triggerSet(){ //Function to setting up the triggers for current project
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ui = SpreadsheetApp.getUi(); //Get the UI for setting trigger
var triggers = ScriptApp.getProjectTriggers(); //Get the current project's trigger
var respond = ui.alert('Setting up new trigger', ui.ButtonSet.OK_CANCEL); //Set the UI prompt message and 'OK/CANCEL' buttons
if(respond ==ui.Button.OK && triggers <=1){ //Set the trigger if button 'OK' is clicked and prevent trgger to be installed more than 1
ScriptApp.newTrigger('onChanges').forSpreadsheet(ss).onChange().create(); //Line for creating the trigger based on changes that made in google sheet
}
else if (respond == ui.Button.CANCEL){ //If 'CANCEL' button is clicked will alert user no trigger installed
ui.alert('No new trigger have been installed');
}
else { ui.alert('No new trigger have been installed') //If close button is clicked will alert user no trigger installed
}
}
function delTrigger(){ //Setup for deleting trigger
var ui= SpreadsheetApp.getUi();
try{
var triggers = ScriptApp.getProjectTriggers();
ScriptApp.deleteTrigger(triggers[0]); //Choosing the trigger to be deleted
ui.alert('Your trigger have been deleted');
}
catch(e){
ui.alert('No trigger have been set!'); //If there is no trigger have been set, it will throw this alert to user.
}
}
上面这一行的说明:
- “onChange”是将被触发的函数名
- “key”是与电子表格绑定的表单的键/唯一id
希望这有助于你的触发,如果有任何评论在这里 您可以为文档的所有者创建触发器,但不能为任何其他人创建触发器,即使您已将其共享给其他人。这很棘手,因为它仍然会将更改通知电子邮件发送给所有者,但不会发送给其他编辑器。
ScriptApp.newTrigger('onChanges').forForm(key).onFormSubmit().create();