Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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 错误:strictValidationFailed_Javascript_Google Apps Script - Fatal编程技术网

Javascript 错误:strictValidationFailed

Javascript 错误:strictValidationFailed,javascript,google-apps-script,Javascript,Google Apps Script,我试图通过doGet()函数访问电子表格,当从表单提交中收到电子邮件的用户单击链接时,会执行该函数。我想我无法从doGet()调用getActiveSpreadsheet。所以我通过链接发送了电子表格id和行号,然后通过openById调用了我需要的电子表格,但是当我这样做时,我得到了一个奇怪的错误“strictValidationFailed”。就是这样,这就是它所说的错误。它没有给出行号或错误类型。似乎因为这个错误是在我开始使用openById功能时出现的,所以这个错误可能与此有关。我在下面

我试图通过doGet()函数访问电子表格,当从表单提交中收到电子邮件的用户单击链接时,会执行该函数。我想我无法从doGet()调用getActiveSpreadsheet。所以我通过链接发送了电子表格id和行号,然后通过openById调用了我需要的电子表格,但是当我这样做时,我得到了一个奇怪的错误“strictValidationFailed”。就是这样,这就是它所说的错误。它没有给出行号或错误类型。似乎因为这个错误是在我开始使用openById功能时出现的,所以这个错误可能与此有关。我在下面附上与此相关的代码片段

function onFormSubmit(event) { //On form submission send an email to the approver. 
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var approvalsheet = spreadsheet.getSheetByName("Approval Worksheet");
//Get values that have to be put on the email.
var timestamp = event.values[0]; 
var username = event.values[1]; 
var campus = event.values[2];
var gltype = event.values[3]; 
var fullname = event.values[4];
var eMailAdd = event.values[5];
var description = event.values[6];
var replacement = event.values[7];
var usage = event.values[8];
var members = event.values[9];
var notes = event.values[11];
var initialowner = event.values[12];
//The service url that is required for approval on the email.
var serviceurl = //hiding the service URL
serviceurl+='&spreadsheetId='+spreadsheet.getId();
serviceurl+='&row='+approvalsheet.getLastRow();
//Setting the message that goes on the email sent to the approver.
var message = 'There is a new Submission to the UAF List or Group aprooval  Workflow\n\n\n'+'You can aproove this request here: '+serviceurl+
  '\n\nTime of Submission: '+timestamp+'\n\nSubmitter Username: '+username
  +'\n\nCampus: '+campus+'\n\nFull Name: '+fullname+'\n\nMiddle Portion of Email Address: '+eMailAdd
  +'\n\nDescription of the List/Group: '+description + '\n\nIs this replacing an existing eMail List or Group? '
  +replacement+'\n\nUsage: '+usage+'\n\nAnticipated number of members: '+members+'\n\nBrief notes about the request :'
  +notes+'\n\nAre you the initial owner :'+initialowner;
//Title for the mail sent.
var title = 'New Submission at '+timestamp;
//Email address for the approver that gets the submission notification.
var mailAdd = 'rssimon@alaska.edu'
//Sending Email to the approver.    
MailApp.sendEmail(mailAdd, title, message);
}


function doGet(e) //On hitting approve button in the mail.
{
//retrieving spreadsheet ID from the approval link.
var spreadsheet = SpreadsheetApp.openById(e.parameter['spreadsheetId']);
//if (spreadsheet != null) {
var approvalsheet = spreadsheet.getSheetByName("Approval Worksheet");
//}
var row = e.parameter['row'];//retreiving row value that came from the approval link.
//if(spreadsheet!=null)
//{
approvalsheet.getRange(row, 17).setValue('Yes');//Setting the approval value on the spreadsheet to Yes.
approvalsheet.getRange(row, 17).setBackground('White');//Setting the approval box color to white.
//}
//Creating UiApp for approval notification.
var app = UiApp.createApplication(); //Create an instance of UiApp
var label = app.createLabel(); //Create a lable on the UiApp
label.setText('The list or group was approved');//Set text on the Label.
app.add(label);//Add label to the UiApp instance.
return app;
}
我已经测试了您的代码(doGet部分),它对我来说运行良好。你确定你在做这个吗

无论如何,尝试将所有内容包装在一个try-catch中并解析错误stacktrace,这可能会有所帮助,例如

函数doGet(e){
试一试{
//所有的电子表格代码
}捕捉(错误){
stack=parseErr(err);
if(!app)//可能是在“createApplication”之后出现错误
app=UiApp.createApplication();
返回app.add(app.createLabel(stack));
}
}
//尝试将stacktrace错误解析为更好的格式
函数parserr(e){
var-ret;
如果(e!==未定义和&e!==空和&e.stack){
ret=e.name+':'+e.message+'\n堆栈跟踪:\n';
var stack=e.stack.replace(/\n/g',).match(/:\d+(\([^\)]+\)?/g);
for(堆栈中的变量i)
ret+=stack[i]。替换(/[\(\):]/g',)。拆分(/).reverse().join(“:”)+“\n”;
}否则
ret=e;
返回ret;
}

该错误似乎与电子表格中的数据验证有关。您能否检查以确保您试图写入电子表格的值没有违反任何数据验证规则?

请帮助我修复此错误并从doGet()函数中获取所需的电子表格。这是一个运行时错误,因此仅运行代码段可能没有帮助。但是,是的,谢谢你给了我解析错误stacktrace的想法。为了其他用户的利益,你能详细说明问题的根源吗?你是在写没有验证的值吗?实际上我是在尝试更改单元格的背景色。但是工作表被设置为具有特定值的特定背景色,即存在一对背景色值。当我自己更改背景颜色时,设置的背景颜色和值对不匹配,导致strictValidationFail。但我认为,一般来说,strictValidationFail错误是指脚本试图设置一个值,但由于单元格上的验证规则,该值被工作表拒绝。