Google apps script &引用;google.script.run.function“;不从htmlservice传递值

Google apps script &引用;google.script.run.function“;不从htmlservice传递值,google-apps-script,Google Apps Script,我知道已被标记为已修复,但我似乎无法将任何参数从我的htmlservice表单传递到我的google apps脚本。以下是我尝试过的: <my html file> <form id="myForm"> <input name="aField" id="aField"> <input type="button" id="submit" value="submit" onclick = "sendData()"> </form>

我知道已被标记为已修复,但我似乎无法将任何参数从我的htmlservice表单传递到我的google apps脚本。以下是我尝试过的:

<my html file>
<form id="myForm">
  <input name="aField" id="aField">
  <input type="button" id="submit" value="submit" onclick = "sendData()">
</form>

<script>
function sendData() {
   google.script.run.processForm(document.getElementById("myForm"));
}
</script>
</my html file>

<google apps script>
   function processForm(value) {
      var range = SpreadsheetApp.openById("1234").getRangeByName("testRnage");
      range.setValue(value.aField);
    }
   </google apps script>

函数sendData(){
google.script.run.processForm(document.getElementById(“myForm”);
}
函数processForm(值){
var range=SpreadsheetApp.openById(“1234”).getRangeByName(“testRnage”);
范围.设置值(值.远场);
}
使用

也不起作用

这两种方法都会导致以下浏览器错误:未捕获的ScriptError:TypeError:无法调用null的方法“setValue”。


感谢您的帮助。谢谢。

我已经成功地做到了:

var invoice = new Object();

invoice.customerCode = selectedCustomer.value;
invoice.discount = document.getElementById('discount').value;
invoice.items = blah, blah, blah . . . 

var jsonInvoice = JSON.stringify(invoice);

google.script.run.recordInvoice(jsonInvoice);
。。。服务器上有了这个

function recordInvoice(jsonInvoice) {
    var theInvoice = eval("(" + jsonInvoice + ")");
    var cust = theInvoice.customerCode;

如果这看起来不完整,请随时要求详细说明。

我不想这么说,但由于我的代码输入错误,它无法工作。我试图访问定义范围为“testRnage”而不是“testRange”。谢谢您的帮助。我一次又一次地梳理代码,但总是漏掉。我也是GAS新手,所以我没有完全理解这个错误,这实际上现在是有道理的。哦,糟了,我看到了“testRnage”,但在你准备文章时,我认为它是一个打字错误。嗯,对不起。同时,我强烈建议您考虑使用JSON.StrugI化,您的代码将变得更加清晰和简单。如果您觉得您的问题(既然您发现它是一个简单的键入,现在就没用了),则堆栈堆栈溢出,您可以自由删除它。