【发布时间】:2021-06-13 18:10:56
【问题描述】:
所以我正在构建一个邮件合并工具,它工作正常。
使用硬编码输入测试触发器可以正常工作:
function test(){
sendEmails("TEST MAILMERGE FROM DRAFT")
}
如果我提示输入框(显示代码的相关部分),它也可以正常工作。
function sendEmails(subjectLine,sheet=SpreadsheetApp.getActiveSheet()) {
if (!subjectLine) {
subjectLine = Browser.inputBox(
"Mail Merge",
"Type or copy/paste the subject line of the Gmail " +
"draft message you would like to use:",
Browser.Buttons.OK_CANCEL
);
if (subjectLine === "cancel" || subjectLine == "") {
// if no subject line finish up
return;
}
}
但是,尝试成为聪明的裤子并让菜单动态填充主题行,如下所示:
function onOpen() {
// get the UI for the Spreadsheet
const ui = SpreadsheetApp.getUi();
// add the menu
const menu = ui.createMenu("TEST");
// get the drafts from Gmail
let drafts = GmailApp.getDraftMessages();
// for each draft, create a new menu item
drafts.forEach((draft) => {
// add the drafts to be triggered using the following: addItem(caption: string, functionName: string)
menu
.addItem(
draft.getSubject().toString(),
'sendEmails("' + draft.getSubject().toString() + '")'
)
.addToUi();
});
}
但是,这不起作用。它出现以下错误:
找不到错误脚本函数:sendEmails(TEST MAILMERGE FROM DRAFT)
在我看来应该可行。由于上面硬编码的测试触发器有效。 我在这里傻吗?据我所知,这应该有效吗?但事实并非如此。
当/如果我得到它的工作,我会签入以说明没有主题的“垃圾”草稿。不过现在只是想让它实际工作。
【问题讨论】:
标签: javascript google-apps-script google-sheets gmail-api google-sheets-api