How to pass parameter(s) to timed trigger function in library script

半腔热情 提交于 2019-11-29 09:41:38

Properties are a not-shared resource; each script has their own set of Properties which are not shared with other scripts. This behaviour affects how you can handle properties in a Library, as described in Resource Scoping.

A not-shared resource means that both library and the including script have built-in access only to their instance of the resource. However, a library can provide access to its not-shared resources by having explicit functions that operate on them.

In other words; the library's not-shared properties can be exposed to the main script by library functions.

This function can be used to set up the operating parameters for your library trigger function:

/**
 * Set name,value pairs of parameters for library function.
 *
 * @param {Object}  parameters  Object with named properties to be
 *                              used as library function parameters.
 */
function setParameters( parameters ) {
  var props = PropertiesService.getUserProperties();
  for (var key in parameters) {
    var value = parameters[key];
    props.setProperty(key, value);
  }
}

You'd use it like this:

function startOnce(){
  var uProps = {
    'Maker':'Honda',
    'Number':'US-xxx'
  });

  Library1.setParameters(uProps);
  Library1.carHistory();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!