6

I going to show my problem with an example:

I have a button. When clicked, it creates a mail draft based on the TextInputFields in the add-on. I have a validate function, which can say if the fields filled right or not.

If I want to notify the user somehow about the wrong fields, I have to create a notify or rebuild the card with error information. These actions can be returned in a normal Action, but not with a composeAction (because composeAction has to return with builded draft), so I have to register a composeAction and a simple action to the button.

When I clicked this kind of button, only one of the action execute and the other do nothing.

Some code about how I tried to implement:

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

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;
}

Mostly the simple action run, and the compose do nothing. If I place Logger.log() functions in the callback function, only one appears on api log.

Anyone have tried before validate and create draft at the same click?

Kos
  • 4,890
  • 9
  • 38
  • 42

1 Answers1

0

How about this:

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);
}
Cooper
  • 59,616
  • 6
  • 23
  • 54