0

フォーム送信からメールを受け取ったユーザーがリンクをクリックしたときに実行される 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;
}
4

2 に答える 2

2

このエラーは、スプレッドシートのデータ検証に関連しているようです。スプレッドシートに書き込もうとしている値がデータ検証規則に違反していないことを確認できますか?

于 2012-06-04T15:04:42.563 に答える
0

私はあなたのコード (doGet 部分) をテストしましたが、うまくいきました。これを正確に実行していると確信していますか?

とにかく、try-catch ですべてをラップし、エラー スタック トレースを解析してみてください。

function doGet(e) {
  try {
    //all your spreadsheet code
  } catch(err) {
    stack = parseErr_(err);
    if( !app ) //maybe the error is after you've "createApplication"
      app = UiApp.createApplication();
    return app.add(app.createLabel(stack));
  }
}

//Try to parse errors stacktrace into a nicer format
function parseErr_(e) {
  var ret;
  if( e !== undefined && e !== null && e.stack ) {
    ret = e.name +': '+e.message+' \nStacktrace: \n';
    var stack = e.stack.replace(/\n/g,'').match(/:\d+( \([^\)]+\))?/g);
    for( var i in stack )
      ret += stack[i].replace(/[\(\):]/g,'').split(/ /).reverse().join(':') + ' \n';
  } else
    ret = e;
  return ret;
}
于 2012-06-02T03:07:36.277 に答える