如何解决Google Apps Scripts 使用撰写同时更新主题和抄送 修改后的脚本:注意:参考:
我想打开撰写 UI 并能够同时更新草稿主题/收件人/和抄送,而不是多次操作。
Google 提供给您的示例代码不是开箱即用的,您需要更正错误。这是工作代码。
/**
* Compose trigger function that fires when the compose UI is
* requested. Builds and returns a compose UI for inserting images.
*
* @param {event} e The compose trigger event object. Not used in
* this example.
* @return {Card[]}
*/
function startApp(e) {
return [buildComposeCard()];
}
/**
* Build a card to display interactive buttons to allow the user to
* update the subject,and To,Cc,Bcc recipients.
*
* @return {Card}
*/
function buildComposeCard() {
var card = CardService.newCardBuilder();
var cardSection = CardService.newCardSection().setHeader('Update email');
cardSection.addWidget(
CardService.newTextButton()
.setText('Update subject')
.setonClickAction(CardService.newAction()
.setFunctionName('applyUpdateSubjectAction')));
cardSection.addWidget(
CardService.newTextButton()
.setText('Update To recipients')
.setonClickAction(CardService.newAction()
.setFunctionName('applyUpdatetoRecipientsAction')));
cardSection.addWidget(
CardService.newTextButton()
.setText('Update Cc recipients')
.setonClickAction(CardService.newAction()
.setFunctionName('applyUpdateCcRecipientsAction')));
cardSection.addWidget(
CardService.newTextButton()
.setText('Update Bcc recipients')
.setonClickAction(CardService.newAction()
.setFunctionName('applyUpdateBccRecipientsAction')));
return card.addSection(cardSection).build();
}
/**
* Updates the subject field of the current email when the user clicks
* on "Update subject" in the compose UI.
*
* Note: This is not the compose action that builds a compose UI,but
* rather an action taken when the user interacts with the compose UI.
*
* @return {UpdateDraftActionResponse}
*/
function applyUpdateSubjectAction() {
// Get the new subject field of the email.
// This function is not shown in this example.
var subject = ['this is a subject'];
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftSubjectAction(CardService.newUpdateDraftSubjectAction()
.addUpdateSubject(subject))
.build();
return response;
}
/**
* Updates the To recipients of the current email when the user clicks
* on "Update To recipients" in the compose UI.
*
* Note: This is not the compose action that builds a compose UI,but
* rather an action taken when the user interacts with the compose UI.
*
* @return {UpdateDraftActionResponse}
*/
function applyUpdatetoRecipientsAction() {
// Get the new To recipients of the email.
// This function is not shown in this example.
var toRecipients = ['johhny.appleseed@gmail.com'];
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftToRecipientsAction(CardService.newUpdateDraftToRecipientsAction()
.addUpdatetoRecipients(toRecipients))
.build();
return response;
}
/**
* Updates the Cc recipients of the current email when the user clicks
* on "Update Cc recipients" in the compose UI.
*
* Note: This is not the compose action that builds a compose UI,but
* rather an action taken when the user interacts with the compose UI.
*
* @return {UpdateDraftActionResponse}
*/
function applyUpdateCcRecipientsAction() {
// Get the new Cc recipients of the email.
// This function is not shown in this example.
var ccRecipients = ['big.blue@montana.com'];
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftCcRecipientsAction(CardService.newUpdateDraftCcRecipientsAction()
.addUpdateCcRecipients(ccRecipients))
.build();
return response;
}
/**
* Updates the Bcc recipients of the current email when the user clicks
* on "Update Bcc recipients" in the compose UI.
*
* Note: This is not the compose action that builds a compose UI,but
* rather an action taken when the user interacts with the compose UI.
*
* @return {UpdateDraftActionResponse}
*/
function applyUpdateBccRecipientsAction() {
// Get the new Bcc recipients of the email.
// This function is not shown in this example.
var bccRecipients = ['spacer@gmail.com'];
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftBccRecipientsAction(CardService.newUpdateDraftBccRecipientsAction()
.addUpdateBccRecipients(bccRecipients))
.build();
return response;
}
不过
这些链接一次只能使用一个并关闭屏幕。您必须在多个动作中执行所有操作。我希望它能够一次执行多个操作。
例如,如果我单击“更新主题”,操作会起作用并且撰写 UI 屏幕会关闭,但我不想再次打开加载项来添加抄送电子邮件地址。
解决方法
我相信你的目标如下。
- 您想在对话框中一键运行
applyUpdateSubjectAction()
、applyUpdateToRecipientsAction()
、applyUpdateCcRecipientsAction()
和applyUpdateBccRecipientsAction()
的这些函数。
这样的话,下面的修改怎么样?
修改后的脚本:
请修改buildComposeCard()
如下。
function buildComposeCard() {
var card = CardService.newCardBuilder();
var cardSection = CardService.newCardSection().setHeader('Update email');
cardSection.addWidget(CardService.newTextButton().setText('Update email').setOnClickAction(CardService.newAction().setFunctionName('applyUpdateEmail')));
return card.addSection(cardSection).build();
}
并且,请添加以下功能。
function applyUpdateEmail() {
var subject = ['this is a subject'];
var toRecipients = ['johhny.appleseed@gmail.com'];
var ccRecipients = ['big.blue@montana.com'];
var bccRecipients = ['spacer@gmail.com'];
return CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftSubjectAction(CardService.newUpdateDraftSubjectAction().addUpdateSubject(subject))
.setUpdateDraftToRecipientsAction(CardService.newUpdateDraftToRecipientsAction().addUpdateToRecipients(toRecipients))
.setUpdateDraftCcRecipientsAction(CardService.newUpdateDraftCcRecipientsAction().addUpdateCcRecipients(ccRecipients))
.setUpdateDraftBccRecipientsAction(CardService.newUpdateDraftBccRecipientsAction().addUpdateBccRecipients(bccRecipients))
.build();
}
- 在此修改中,您可以在打开的对话框中看到“更新电子邮件”。单击它时,会运行
addUpdateSubject
、addUpdateToRecipients
、addUpdateCcRecipients
和addUpdateBccRecipients
。
注意:
- 当您修改 Google Apps 脚本时,请将部署修改为新版本。这样,修改后的脚本就会反映到附加组件中。请注意这一点。
参考:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。