我不知道应该在哪里发布这个。我希望这是正确的地方。
我有一个Google表单,当表单填写完毕后,回复会自动输入Google表格。由于我是所有者,因此我设置了默认的Google通知,告知我填写Google表单后表单已更改:
流程为:Google表单填写> Google表格已更新,其中包含来自Form>的回复电子邮件通知到我的电子邮件地址
我已将Google表格分享给我公司的其他用户。他们拥有对工作表的编辑权限。我希望此用户在表单发生更改时也会收到通知。
因此,流程将是:填写的Google表格> Google表格已更新,其中包含来自Form>的回复向我的电子邮件通知和其他用户的电子邮件地址
我已经在线搜索,因为Google Apps尚无法进行搜索(它只会通知所有者)。建议在我的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代码电子邮件通知。
我已经在“触发器”部分查看了Google Code网站,但不确定如何编写此部分。 我想我需要在代码上写一个触发器,说明Sheet更改后运行自定义代码。
所以Google表格填写了> Google表格已更新,其中包含来自Form>的回复Google表格中的更改会触发触发器>触发器运行自定义Google代码>其他用户和我收到了自定义Google代码电子邮件通知。
任何人都可以帮助触发代码部分,甚至可以推荐不同的解决方案吗?
感谢。
答案 0 :(得分:0)
您可以在"资源"中添加触发器。 - > "当前项目的触发器"脚本编辑器中的菜单项。
然后按以下格式创建一个触发器:
" myFunction的" - > "来自电子表格" - > " On Change"
答案 1 :(得分:0)
对于触发器,我之前已经制作了类似的代码,但这是针对事件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.
}
}
此行应该替换我所制作的代码中的当前触发器构建器。编辑器,您需要单击任何一个自定义菜单才能激活授权。
ScriptApp.newTrigger('onChanges').forForm(key).onFormSubmit().create();
上面这一行说明:
希望这可以帮助您触发,如果有任何评论在这里。