Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript google.script.run.withSuccessHandler don';t返回值_Javascript_Google Apps Script_Google Sheets_Web Applications - Fatal编程技术网

Javascript google.script.run.withSuccessHandler don';t返回值

Javascript google.script.run.withSuccessHandler don';t返回值,javascript,google-apps-script,google-sheets,web-applications,Javascript,Google Apps Script,Google Sheets,Web Applications,这让我抓狂,代码昨天还在工作,但现在已经不工作了。我试图再次检查所有语法,但问题仍然存在。来自google sheets的服务器端请求在服务器端显示值(Logger.log()),但在客户端返回null!你能帮我找到问题吗 function supervisorLine(lineData){ if (lineData== 'Name Value is not VALID!' ) { console.log("Supervisor Name Issue!"); }

这让我抓狂,代码昨天还在工作,但现在已经不工作了。我试图再次检查所有语法,但问题仍然存在。来自google sheets的服务器端请求在服务器端显示值(
Logger.log()
),但在客户端返回null!你能帮我找到问题吗

  function supervisorLine(lineData){
    if (lineData== 'Name Value is not VALID!' ) {
      console.log("Supervisor Name Issue!");
    } else {
      document.getElementById('Team').value= lineData[7];
      document.getElementById('Shift').value= lineData[12];
      document.getElementById('action').classList.remove("disabled");
      console.log("team "+lineData[7]+" shift "+lineData[12]);
      ////////////////////////////////// need to be Moved somewhere after password check !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      google.script.run.withSuccessHandler(function(quickStat2){console.log(quickStat2)}).loginRecords(lineData[7],lineData[12]);                
    }
  }  
这也是我的服务器端代码

function loginRecords(team,shift){
  var sh = ss.getSheetByName("Attn Rec");
  var result= [];
  var matchRec= sh.getRange("a2:l"+sh.getLastRow()).getValues().filter(function(a){
    return a[1]===shift && a[4].valueOf()==team.valueOf()});
  uniqeLogin = removeDups(matchRec.map(function (a){return a[9]}));
  // Logger.log(uniqeLogin);
  uniqeLogin.forEach(function (a){
    var ary=[team,0 ,shift,"",0,0,0,0,0];
    matchRec.forEach(function (r){
      if(r[9]===a) {
        ary[1]= new Date(r[0]);
        ary[3]= r[8];
        switch (r[3].toString().toLowerCase()) {
          case "off-site work":
          case "hr action":
            ary[8]++;
            break;
          case "present":
          case "late transfer":
          case "transfer":
            ary[4]++;
            break;
          case "no show":
            ary[5]++;
            break;
          case "Sick":
          case "vacation":
            ary[7]++;
            break;
          case "late":
          case "approved delay start":
            ary[6]++;
            break;
          }
        }
      });
    result.push(ary);
  });
  Logger.log(result); 
  return result;
}  
对于重述,
Logger.log(result)
返回我需要的数组,但是
console.log(quickStat2)
返回null

提前感谢。

M

不久前我偶然发现了这个问题,它几乎让我发疯(哦,松散类型JS的乐趣!)。问题是您试图将不可接受类型的数据返回到客户端。通过
google.script.run
调用的函数对返回的内容有限制(例如,您应该避免
Date
实例)

受限类型

目前,您无法返回(有关限制的详细说明,请参阅):

  • 日期
    实例
  • 功能
  • DOM
    元素(尽管允许使用
    form
    解决方案


    更改
    ari[1]=新日期(r[0])
    to
    ary[1]=r[0]
    应该可以做到这一点,只需将
    日期
    解析移到客户端。

    在找到你的答案之前,我正要把头发扯下来。在返回到客户端处理程序之前,不知道日期对象未隐式转换为字符串。非常感谢。