D3FTY
D3FTY

Reputation: 135

Authorization required to perform that action

I am having difficulties right now. I am constantly getting "Authorization required to perform that action" everyday.

The trigger event that I am using is onFormSubmit. I did not edit the code at all after creating the trigger but I am getting this error everyday. When I created the trigger, Google did ask me for approval and permission to allow the trigger. Even so, it kept having this error.

May I know what is the possible cause of this?

 function onFormSubmit(e) {

    if (e.values && !e.values[1]) { return; }

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Form Responses 1");

  var stage1pressUL = sheet.getRange("AI2").getValue();
  var stage1pressLL = sheet.getRange("AJ2").getValue();

  var recipients = ""+sheet.getRange("AH2").getValues();
  var params = new Array();
  var positivelimit = Number.POSITIVE_INFINITY;
  var negativelimit = Number.NEGATIVE_INFINITY;

  for(var i=0; i<sheet.getMaxColumns(); i++){
   params[i] = e.values[i]; 
  }

  console.log(params);

  var paramsInfo = [
    {
      name: "ap2233stage1press", number: 3, min: stage1pressLL, max: stage1pressUL
    },
    {
      name: "ap2234stage1press", number: 4, min: stage1pressLL, max: stage1pressUL
    },
    {
      name: "ap2235stage1press", number: 5, min: stage1pressLL, max: stage1pressUL
    },
    {
      name: "ap2236stage1press", number: 6, min: stage1pressLL, max: stage1pressUL
    },
    ];

  for(var z=0; z<paramsInfo.length; z++){
    var paramsInfoCheck = paramsInfo[z];
    var template = HtmlService.createTemplateFromFile(paramsInfoCheck.name);
    template[paramsInfoCheck.name] = params[paramsInfoCheck.number];
    template.recorded = params[31];

    if((params[paramsInfoCheck.number] != "-5") && ((params[paramsInfoCheck.number] < paramsInfoCheck.min) || (params[paramsInfoCheck.number] > paramsInfoCheck.max))){

      MailApp.sendEmail(recipients,
    "40K RO Parameter Out of Range Notification",
     "",{htmlBody: template.evaluate().getContent()});
    }
}
}

Upvotes: 0

Views: 335

Answers (1)

ziganotschka
ziganotschka

Reputation: 26836

The problem comes from your line

var recipients = ""+sheet.getRange("AH2").getValues();

Explanation

MailApp.sendEmail() accepts comma separated strings as parameter for multiple recipients.

However, getValues() returns you a nested array instead of a string, e.g.

[[[email protected], [email protected]]]

Solution

Replace getValues() by getValue() or (makes sense if your range contains more than one cell) by getValues()[0][0]. This will return

[email protected], [email protected]

without brackets.

Upvotes: 1

Related Questions