Cardservice to update Textinput value

326 views
Skip to first unread message

Dorabajji

unread,
Jun 21, 2022, 12:55:43 PM6/21/22
to Google Apps Script Community
One doubt with respect to cardservice.
I am trying to set onchange for text input. 
i am not able to change the value rather i had to use navigation to show updated card.
is there possibility to update text input field without updating card or using navigation?
i have declared global variable for the text input field and adding it as a section in the card.
Does anyone guide me a better way. as through this way my button functionality does not work.
As after this textinput, i have a button. and when that button is clicked after inputing, this runs and on clicking second time action for that button works.
I have even keep sleep time, but the action is not through on first click, as it is executing onchange.

Clark Lind

unread,
Jun 24, 2022, 2:10:59 PM6/24/22
to Google Apps Script Community
I was able to get this to work:

function myNewFunction(e) {
  console.log(e)
}

function onGmailMessage(e) {
    var accessToken = e.messageMetadata.accessToken;
    GmailApp.setCurrentMessageAccessToken(accessToken);
    var messageId = e.messageMetadata.messageId;

     var textInput = CardService.newTextInput()
            .setFieldName('myInput')
            .setTitle('Text input')
            .setMultiline(false)
            .setOnChangeAction(CardService.newAction()
                .setFunctionName("myNewFunction")
                .setParameters({
                  'input': 'myInput'
                })
            );
                                
    var cardSection = CardService.newCardSection()
        .addWidget(textInput);
        
    var card = CardService.newCardBuilder()
        .setName("HomePage")
        .addSection(cardSection)
        .build();
    return card;

Clark Lind

unread,
Jun 24, 2022, 2:57:44 PM6/24/22
to Google Apps Script Community
So the above gets the output of the text field change, but I have no idea how to return the text back to the card itself. Sorry the above isn't much help.
Reply all
Reply to author
Forward
0 new messages