1

Documentation shows examples of creating a SelectionInput item: https://developers.google.com/apps-script/reference/card-service/selection-input

Question: How to read value of SelectionInput in an action handler? Like:

var dropdown = CardService.newSelectionInput()
  .setType(CardService.SelectionInputType.DROPDOWN)
  .setTitle("Status")
  .setFieldName("dd_status")
  .addItem("A", 1, status == 1)
  .addItem("B", 2, status == 2)
  .addItem("C", 3, status == 3)
  .setOnChangeAction(CardService.newAction()
  .setFunctionName("handleStatusDropdownChange").setParameters({'thread_id': thread_id}));

Now, how to access dd_status in handleStatusDropdownChange? It does not seem to appear in parameters, when the handler is defined like:

function handleStatusDropdownChange(e) {
    var parameters = e.parameters;
}

Where is it?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Marcin
  • 4,080
  • 1
  • 27
  • 54

1 Answers1

1

All the input values are being held inside the event object passed to the handler function.

function handleStatusDropdownChange(e) {
    var dd_status = e.commonEventObject.formInputs.dd_status[""].stringInputs.value[0];
}

Notice that e.formInput.dd_status will also work, but the docs states its deprecated.

For more info: https://developers.google.com/gsuite/add-ons/concepts/event-objects#common_event_object Under "Common event object" title.

Shay Yzhakov
  • 975
  • 2
  • 13
  • 31