当调用更新时,它会运行一个名为update的脚本,您可以在以下代码片段中看到:
HTML中的:
function updDate(date){
console.log("update called");
google.script.run.withSuccessHandler(myReturnFunction).updDate(date);
//Crossover.libTest();
console.log("crossover should have been called");
}
function myReturnFunction(garbage){
console.log("Returned: "+ garbage);
/*for (var i = 0; i < whatGotReturned.length; i++) {
document.getElementById("field_"+[i]).innerHTML = whatGotReturned[i];
}*/
}
在Google脚本中:
function updDate(date){
var searchString = date;
var s2 = SpreadsheetApp.openById("0AnDrS3YbyWoLdC15aktnMTluUkQ3dWhNTFlyQXBPOFE");
var data = s2.getActiveSheet().getDataRange().getValues();
var k;
for (var i in data) {
for (var j in data[i]) {
if (i !=0){
if(data[i][j] != ""){
if(j == 4){
var ssDate = Utilities.formatDate(data[i][j], "GMT", "MM/dd/yyyy");
if(date == ssDate){
k= i
var p = data[i].length
}//conclude if
}//conclude if (j==4)
}//conclude if(data[i][j] != "")
}//conclude if (data[i][j] != "")
} //conclude for (var j in data[i])
}//conclude for (var i in data)
//Logger.log("K is: "+k)
var valuesToSnd = new Array();
var q = 1
while (q <= p){
//if(data[k][q] !=""){
valuesToSnd[q] = data[k][q];
//document.getElementById("field_"+[q]).innerHTML = data[k][q];
//}
q++
}
Logger.log("Values to Send: "+valuesToSnd);
return valuesToSnd;
}
Google脚本会按照以下方式记录数组:
[14-08-26 08:47:03:950 EDT]值发送:,BABS仅在 AFM ,, BABS,2014年8月8日星期五00:00:00 GMT-0400(EDT),No Unload Necissary,https://docs.google.com/forms/d/1yBiXtjTpXs85BNs5Lsj0zGQtDtxghm6-e2lRebB4saw/viewform?edit=ChM1NzYwNDkwNTY0Nzg2NjY5MTI4EJKj-OTR3ejNhwE,,https://docs.google.com/document/d/15f2HjJjNTxjlLZOkB2BOe8nY9ZlImmaAaSSnhViAa4I/edit,,Thu 2014年8月7日15:30:00 GMT-0400(美国东部时间),1899年12月30日星期六14:30:00 GMT-0500 (EST),18月12日星期六1899 15:00:00 GMT-0500(EST),1899年12月30日星期六18:45:00 GMT-0500(EST),5 Ton 35,No,No ,,,,, All Singers,Not 需要,,需要的话,所需,,,, https://docs.google.com/spreadsheet/ccc?key=0AnDrS3YbyWoLdDdSel9RVVNVMGhDakwxMmdueGc4WGc&usp=drive_web#gid=4,,No,AFM,https://www.mediafire.com/folder/dp788cvtbexsf/,
脚本运行后的某个地方,控制台会返回以下错误:
未捕获的ScriptError:脚本已完成但返回的值为 不支持的返回类型。
代码是否有问题,或者数组中是否存在函数不“喜欢”的字符?
谢谢,
洛伦
这有效:
var valuesToSnd = new Array();
var q = 0
while (q <= p){
//if(q!=0){
if(data[k][q] !=""){
if (q==11){
var trudeptTime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = trudeptTime;
}
else if(q==12){
var lITime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = lITime;
}
else if (q==13){
var sCTime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = sCTime;
}else{
valuesToSnd[q] = q+ ": "+ data[k][q];
}
}else{
//valuesToSnd[q]= q + "Nothing";
}
/*}else{
valuesToSnd[q]= q+ ": "+ data[k][q];
}*/
q++
}
Logger.log("Values to Send: "+valuesToSnd);
return valuesToSnd;
}
这不是:
var valuesToSnd = new Array();
var q = 0
while (q <= p){
//if(q!=0){
if(data[k][q] !=""){
if (q==11){
var trudeptTime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = trudeptTime;
}
else if(q==12){
var lITime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = lITime;
}
else if (q==13){
var sCTime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = sCTime;
}else{
valuesToSnd[q] = data[k][q];
}
}else{
//valuesToSnd[q]= q + "Nothing";
}
/*}else{
valuesToSnd[q]= q+ ": "+ data[k][q];
}*/
q++
}
Logger.log("Values to Send: "+valuesToSnd);
return valuesToSnd;
}
下面的一些评论是一个或两个调整后的日志:
14-08-27 12:51:51:572 EDT] k: 26 q: 0Timestamp data: Mon Jul 14 2014 11:08:15 GMT-0400 (EDT)
[14-08-27 12:51:51:573 EDT] k: 26 q: 1Gig Name data: BABS only at AFM
[14-08-27 12:51:51:573 EDT] k: 26 q: 2Program Name data:
[14-08-27 12:51:51:573 EDT] k: 26 q: 3Groups Involved data: BABS
[14-08-27 12:51:51:574 EDT] k: 26 q: 4Gig Date data: Fri Aug 08 2014 00:00:00 GMT-0400 (EDT)
[14-08-27 12:51:51:574 EDT] k: 26 q: 5Notes data: No Unload Necissary
[14-08-27 12:51:51:574 EDT] k: 26 q: 6Gig Coordination Form Link data: https://docs.google.com/forms/d/1yBiXtjTpXs85BNs5Lsj0zGQtDtxghm6-e2lRebB4saw/viewform?edit=ChM1NzYwNDkwNTY0Nzg2NjY5MTI4EJKj-OTR3ejNhwE
[14-08-27 12:51:51:575 EDT] k: 26 q: 7Announcer Name data:
[14-08-27 12:51:51:575 EDT] k: 26 q: 8Program Notes Link data: https://docs.google.com/document/d/15f2HjJjNTxjlLZOkB2BOe8nY9ZlImmaAaSSnhViAa4I/edit
[14-08-27 12:51:51:575 EDT] k: 26 q: 9Jump to page data:
[14-08-27 12:51:51:576 EDT] k: 26 q: 10Truck Load data: Thu Aug 07 2014 15:30:00 GMT-0400 (EDT)
[14-08-27 12:51:51:576 EDT] k: 26 q: 11Truck Departure Time data: Sat Dec 30 1899 14:30:00 GMT-0500 (EST)
[14-08-27 12:51:51:577 EDT] k: 26 q: 12Load In Time data: Sat Dec 30 1899 15:00:00 GMT-0500 (EST)
[14-08-27 12:51:51:578 EDT] k: 26 q: 13Sound Check Time data: Sat Dec 30 1899 18:45:00 GMT-0500 (EST)
[14-08-27 12:51:51:579 EDT] k: 26 q: 14Trucks to be used data: 5 Ton 35
[14-08-27 12:51:51:579 EDT] k: 26 q: 15LRS Support Required data: No
[14-08-27 12:51:51:579 EDT] k: 26 q: 16LRS Request submitted data: No
[14-08-27 12:51:51:580 EDT] k: 26 q: 17Date Request submitted to Band VCO/VNCO data:
[14-08-27 12:51:51:580 EDT] k: 26 q: 18LRS Confirmation Number data:
[14-08-27 12:51:51:581 EDT] k: 26 q: 19Unload Truck data:
[14-08-27 12:51:51:581 EDT] k: 26 q: 20Jump to page data:
[14-08-27 12:51:51:581 EDT] k: 26 q: 21BABS Crew Members data: All Singers
[14-08-27 12:51:51:581 EDT] k: 26 q: 22BABB Crew Members data: Not needed
[14-08-27 12:51:51:582 EDT] k: 26 q: 23Jump to page data:
[14-08-27 12:51:51:582 EDT] k: 26 q: 24Input List data: Needed
[14-08-27 12:51:51:583 EDT] k: 26 q: 25Pack List data: Needed
[14-08-27 12:51:51:583 EDT] k: 26 q: 26Pack list Link (If Applicable) data:
[14-08-27 12:51:51:583 EDT] k: 26 q: 27Singers Standing arrangment data:
[14-08-27 12:51:51:583 EDT] k: 26 q: 28Jump to page data:
[14-08-27 12:51:51:584 EDT] k: 26 q: 29Input List Link (if Applicable) data: https://docs.google.com/spreadsheet/ccc?key=0AnDrS3YbyWoLdDdSel9RVVNVMGhDakwxMmdueGc4WGc&usp=drive_web#gid=4
[14-08-27 12:51:51:584 EDT] k: 26 q: 30 data:
[14-08-27 12:51:51:584 EDT] k: 26 q: 31Singers Stands required data: No
[14-08-27 12:51:51:585 EDT] k: 26 q: 32Gig Location data: AFM
[14-08-27 12:51:51:585 EDT] k: 26 q: 33Media Link data: https://www.mediafire.com/folder/dp788cvtbexsf/