How to get value of the checked checkbox value for google calendar add on?

Viewed 39

I am making a checkbox of the list of guests in a google calendar event.
I want to know how can I get the value of the checked checkboxes in my code?
This is what I've written so far

function createCard(title, guest){
var checkboxGroup = CardService.newSelectionInput()
.setType(CardService.SelectionInputType.CHECK_BOX)
.setTitle("Select guests for creating a visitor pass")
.setFieldName("checkbox_field")
for(var i = 0; i < guest.length; i++){
  checkboxGroup.addItem(guest[i], guest[i], false)
}
var button = CardService.newTextButton()
  .setText('Create Visitor Pass')
  .setOpenLink(CardService.newOpenLink().setUrl("https://automation-help.com/http-requests-google-app-script/"))
  .setTextButtonStyle(CardService.TextButtonStyle.FILLED);

var buttonSet = CardService.newButtonSet()
  .addButton(button)

var section = CardService.newCardSection()
  .addWidget(checkboxGroup)
  .addWidget(buttonSet)
var card = CardService.newCardBuilder()
  .addSection(section)

return card.build();
}
1 Answers

A map containing the current values of the widgets in the displayed card. The map keys are the string IDs assigned with each widget, and each value is another wrapper object with a single "" key. The structure of the map value object is dependent on the widget type:

  • Multi-valued widgets (for example, checkbox groups): a list of strings. Example: for a multi-value widget with participants as its ID, access the value array with: e.commonEventObject.formInputs.participants[""].stringInputs.value.
  • This object contians the parameter checkbox_field that is an array containing the values of the checkboxes that are curerntly ticked

Example:

function createCard(title, guest){
  var checkboxGroup = CardService.newSelectionInput()
  .setType(CardService.SelectionInputType.CHECK_BOX)
  .setTitle("Select guests for creating a visitor pass")
  .setFieldName("checkbox_field")
  for(var i = 0; i < guest.length; i++){
    checkboxGroup.addItem(guest[i], guest[i], false)
  }

  checkboxGroup.setOnChangeAction(selectionAction);
  var selectionAction = CardService.newAction().setFunctionName("onTick");
  ...
}



function onTick(e) {
  console.log("e.formInputs.checkbox_field: " + JSON.stringify(e.formInputs.checkbox_field));
  var tickedCheckBoxes = e.formInputs.checkbox_field;
  tickedCheckBoxes.forEach(function(checkBox){
   if(checkBox){
     console.log("Checkbox " + checkBox + " is ticked.")
   }
  })
}
Related