只能执行一种类型的操作?

Ágo*_*ner 6 google-apps-script gmail-addons

我将用一个例子来展示我的问题:

我有一个按钮.单击时,它会根据TextInputFields加载项中的内容创建邮件草稿.我有一个验证功能,可以说明字段填写是否正确.

如果我想以某种方式通知用户有关错误的字段,我必须创建一个通知或重建带有错误信息的卡.这些操作可以正常返回Action,但不能返回composeAction(因为composeAction必须使用构建的草稿返回),所以我必须向composeAction按钮注册一个简单的操作.

当我点击这种按钮时,只有一个动作执行而另一个动作无效.

关于我如何尝试实现的一些代码:

section.addWidget(CardService.newTextButton()
  .setText('Validate and Create')
  .setComposeAction(CardService.newAction().setFunction('doIt'), CardService.ComposedEmailType.STANDALONE_DRAFT)
  .setOnClickAction(CardService.newAction().setFunction('notify')));
Run Code Online (Sandbox Code Playgroud)

ActionFunctions:

function doIt(event){
  validate the event['formInput'] object;
  if(valid the formInput)
    create  andr return the draft;
  else
    return null;
}

function notify(event){
  validate the event['formInput'] object;
  if(valid the formInput)
    return null;
  else
    return notify or rebuilded card with error info;
}
Run Code Online (Sandbox Code Playgroud)

主要是简单的动作运行,而compose什么都不做.如果我将Logger.log()函数放在回调函数中,则只有一个出现在api日志中.

有人在验证之前尝试过并在同一次点击中创建草稿吗?

Coo*_*per 0

这个怎么样:

var action=CardService.newAction().setFunctionName('myFunction');
var validateCreateButton=CardService.newTextButton()
.setText('Validate & Create')
.setOnClickAction(action);
section.addWidget(validateCreateButton);


function myFunction(e) {
  doit(e);
  notify(e);
}
Run Code Online (Sandbox Code Playgroud)