Reputation: 379
I'm working on a card service script and am having some difficulties with the action handler.
I have two drop downs on a CardService, one is product_category and the other is sub_category.
// created as (and the following sub_category)
var productCategory = CardService.newSelectionInput()
.setType(CardService.SelectionInputType.DROPDOWN)
.setTitle("Product Category")
.setFieldName("product_category")
I then created a button below, so when an action is taken, it will submit the data to a spreadsheet (that functionality i have). What i'm missing here and can't seem to dig up in the docs is how i can grab the product_category and sub_category and pass them in as parameters.
// my action caller on the button
var newButton = CardService.newTextButton()
.setText('Submit')
.setOnClickAction(CardService.newAction()
.setFunctionName("sendToSpreadsheet"));
// adding button to section
section.addWidget(CardService.newButtonSet().addButton(newButton));
//i then have my function which takes product and sub product
function sendToSpreadsheet(product_category, sub_category){
// process events here
}
My question is how do i pass the product_category and sub_category to the sendToSpreadsheet function? Been basing off the docs here: https://developers.google.com/apps-script/reference/card-service/card-action
Upvotes: 2
Views: 2503
Reputation: 379
Update:
Figured this one out, there is a formInputs
object in the callback's e
object that you can use to access in the function.
I switched my sendToSpreadsheet to the following
function sendToSpreadsheet(e){
var res = e['formInputs'];
var productCat = res['product_category'];
var productSubCat = res['product_sub_category'];
// rest of code...
}
Upvotes: 2
Reputation: 57
If the above is not working you can use
e.formInputs.product_category;
e.formInputs returns a JSON Object and you can fetch the data by the Field name provided.
Upvotes: 1