简体   繁体   中英

How to get value of Card Service elements in click event within Google Apps Script add-on?

How do we read the values of the UI elements from the click event for the Submit button? Have I missed something simple? Aka, going into this I assumed there was an Apps Script object that would help read the Card UI elements? Am I mistaken, and have to revert to basic javascript here, if so, any examples within the GApps space as I new to this would help out. thanks.

I have a Google Workspace Addon using Apps Script and the Card Service for the UI. Addon is run via icon from Gmail, Sheets, etc. The Card UI collects a few simple values with text fields and a few dropdowns. When done and clicking the Submit button we'd like to submit those values to an external web service. (Calling another external web service for the dropdown values works just fine, btw)

setupfunc() {
    let cardSection1TextInput1 = CardService.newTextInput()
        .setFieldName('name')
        .setTitle('Name')
        .setMultiline(false);

... ...

    let cardSection1ButtonList1Button1Action1 = CardService.newAction()
        .setFunctionName('processClick');


    let cardSection1ButtonList1Button1 = CardService.newTextButton()
        .setText('Submit')
        .setBackgroundColor('#66b73a')
        .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
        .setOnClickAction(cardSection1ButtonList1Button1Action1);
}

...

function processClick(e) 
{
   // Is there a Card Service/Apps Script helper to read the UI input value for name?
   // can't appear to grab values off of e of any relevance so far...   

   var userdata_name = ???? 

   var response = UrlFetchApp.fetch("url", options); // this will just work once we have data

}

e.formInputs is the answer I found buried in official Google sample code. So, e.formInputs.name is what I need.

Did a search with formInputs and found this post already asked: link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM