2

I need to pass the value of the selectbox to it's widget's handler function

var payment = CardService.newSelectionInput()
  .setType(CardService.SelectionInputType.DROPDOWN)
  .setTitle("payment mode")
  .setFieldName("payment_mode")
  .addItem("Debit card", "contact", false)
  .addItem("Net banking", "lead", true)
  .setOnChangeAction(CardService.newAction().setFunctionName("onModeChange"));
section.addWidget(payment);

I expect something like setFunctionName("onModeChange").setParams(payment.value)

tehhowch
  • 9,645
  • 4
  • 24
  • 42
hhsb
  • 560
  • 3
  • 23

1 Answers1

2

I think that your script is almost the correct. You can achieve what you want by modifying a little. In your case, you want to retrieve contact or lead at the function onModeChange. If my understanding is correct, how about this modification?

In your script, you can retrieve the selected values as follows. When an user selects, the selected values are sent to onModeChange, immediately. Please add this function in your script.

function onModeChange(e) {
    console.log(e.formInput.payment_mode)
}

If the user selects Debit card and Net banking, you can retrieve contact and lead at e.formInput.payment_mode, respectively.

If you want to give the additional values when the user selects, please modify

From
.setOnChangeAction(CardService.newAction().setFunctionName("onModeChange"))
To :
.setOnChangeAction(CardService.newAction().setFunctionName("onModeChange").setParameters({key1: "value1"}))

By this modification, at onModeChange(e), you can retrieve the added values by e.parameters.key1.

Note :

  • This sample supposes that both your script works and you can see the select box at the gmail addon. If your script didn't work yet, please tell me.

References :

If I misunderstand your question, I'm sorry.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Works like a charm. I wonder why the documentation does not explain these tiny things. – hhsb May 21 '18 at 08:51
  • @Hari Balaji I think so. When I had used this, I had not been able to find such documents. So I checked the object using ``Logger.log(e)`` and ``console.log(e)``. I would like to think to summarize and publish such information if it is useful for users. – Tanaike May 21 '18 at 11:39
  • Can you look into this also https://stackoverflow.com/questions/50460875/authorising-non-google-services-in-a-gmail-add-on ? – hhsb May 22 '18 at 11:39
  • @Hari Balaji I saw it just now. But I couldn't understand what you want to do. I'm sorry for my poor English skill. – Tanaike May 22 '18 at 22:39
  • I basically was trying to have a login form in my app. But , we dont have here. So I was trying to implement this https://stackoverflow.com/questions/47904710/password-type-field-in-gmail-card-service. I am stuck here. What is 'usercallback' referred to in that answer. Is that a keyword or is it referring to a method ? Can you pls help me with this ? – hhsb May 23 '18 at 02:40
  • @Hari Balaji I'm really sorry I couldn't understand about it. – Tanaike May 23 '18 at 02:49
  • @Hari Balaji I'm sorry I couldn't help. – Tanaike May 23 '18 at 02:59