How do I pass HTML form data to apps script variable?

好久不见. 提交于 2019-12-06 15:43:42

The variable data looks like it is an array. By putting a dot operator, and the word "values" on the end of data, you are trying to invoke a method on the array named "data". But there is no JavaScript method for an array name "values". There is a .valueOf method.

Methods:

  • concat() Joins two or more arrays, and returns a copy of the joined arrays
  • indexOf() Search the array for an element and returns its position
  • join() Joins all elements of an array into a string
  • lastIndexOf() Search the array for an element, starting at the end, and returns its position
  • pop() Removes the last element of an array, and returns that element
  • push() Adds new elements to the end of an array, and returns the new length
  • reverse() Reverses the order of the elements in an array
  • shift() Removes the first element of an array, and returns that element
  • slice() Selects a part of an array, and returns the new array
  • sort() Sorts the elements of an array
  • splice() Adds/Removes elements from an array
  • toString() Converts an array to a string, and returns the result
  • unshift() Adds new elements to the beginning of an array, and returns the new length
  • valueOf() Returns the primitive value of an array

Properties

  • constructor Returns the function that created the Array object's prototype
  • length Sets or returns the number of elements in an array
  • prototype Allows you to add properties and methods to an Array object

If you want the first value indexed in the array named data, use:

data[0]

In other words:

var columnA = data[0];

If it's not an array, but just a string, you may need to convert it to an array.

You can't read values like data.values[0]. Whenever you pass form values to GAS, function parameter doesn't have property like 'values'. Those 'data' parameter will act like a json data. You can access it by name of parameter which you have given in your form, i.e <input type='text' name='user' value=''>. So if you pass this value to GAS, then this can be accessed like data['user'].

Or you can access it in following way too,

var array = [];
for(var i in data) {  // data is a function parameter you have used in your GAS function, addData(data)
  arr.push(data[i]);
}

After having done this, you can use this array, array[], to assign your columns, i.e

var columnA = arr[0];
Logger.log('Start data value: ' + columnA);
var columnB = arr[1];
...
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!