本文介绍了Google应用脚本,Gmail插件获取TextInput值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Google脚本创建了一个简单的gmail插件,因为我在这里遇到了困难,

I have create simple gmail addon using google script,in that i have struggle here,

当我们执行某些操作时如何获取textinput值,我已经检查了文档,找不到任何方法

how to get textinput value when we perform some action,i have checked the document, i couldn't find any methods

TextInput

我尝试过的以下代码,

var card = CardService.newCardBuilder();
  card.setHeader(CardService.newCardHeader().setTitle("Login Here"));
  var section = CardService.newCardSection()
  var cleint_id_Input = CardService.newTextInput()
     .setFieldName("client_id")
     .setTitle("Please enter clinet id")
  var username_Input = CardService.newTextInput()
     .setFieldName("username")
     .setTitle("Please enter username")
  var password_Input = CardService.newTextInput()
     .setFieldName("password")
     .setTitle("Please enter password")
  section.addWidget(cleint_id_Input)
  section.addWidget(username_Input)
  section.addWidget(password_Input)
  Logger.log("Input Value%s",cleint_id_Input)
  //Login action button
  var action = CardService.newAction().setFunctionName('loginCallback');
  section.addWidget(CardService.newTextButton().setText('Login').setOnClickAction(action))  
  card.addSection(section)

我需要在"loginCallback"函数中使用inputText值

i need inputText value in "loginCallback" function

预先感谢

推荐答案

您可以将输入的值作为JSON对象检索.修改后的脚本检索输入的值并显示它们.因此,请根据您的环境进行修改.

You can retrieve the inputted values as JSON object. The modified script retrieves the inputted values and displays them. So please modify this for your environment.

function buildAddOn() {
  var card = CardService.newCardBuilder();
  card.setHeader(CardService.newCardHeader().setTitle("Login Here"));
  var section = CardService.newCardSection()
  var cleint_id_Input = CardService.newTextInput()
    .setFieldName("client_id")
    .setTitle("Please enter clinet id")
  var username_Input = CardService.newTextInput()
    .setFieldName("username")
    .setTitle("Please enter username")
  var password_Input = CardService.newTextInput()
    .setFieldName("password")
    .setTitle("Please enter password")
  section.addWidget(cleint_id_Input)
  section.addWidget(username_Input)
  section.addWidget(password_Input)
  Logger.log("Input Value%s",cleint_id_Input)
  //Login action button
  var action = CardService.newAction().setFunctionName('loginCallback');
  section.addWidget(CardService.newTextButton().setText('Login').setOnClickAction(action))  
  card.addSection(section)
  return card.build() // Added
}

// Added
function loginCallback(e) {
  return CardService.newCardBuilder()
  .setHeader(CardService.newCardHeader().setTitle('sample'))
  .addSection(CardService.newCardSection().addWidget(
    CardService.newKeyValue().setContent(JSON.stringify(e.formInput, null, "  ")))
  )
  .build();
}

输入值:

根据您的情况,loginCallback(e)中的e如下.

{
    "formInput": {
        "password": "###",
        "client_id": "###",
        "username": "###"
    },
    "clientPlatform": "web",
    "messageMetadata": {
        "messageId": "###",
        "accessToken": "###"
    },
    "formInputs": {
        "password": [
            "###"
        ],
        "client_id": [
            "###"
        ],
        "username": [
            "###"
        ]
    },
    "parameters": {}
}

如果我误解了你的问题,对不起.

If I misunderstand your question, I'm sorry.

这篇关于Google应用脚本,Gmail插件获取TextInput值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 20:18