Exception: Action not allowed

74 Views Asked by At

I am trying to create a google apps script mail merge that pulls data from a google sheets to populate fields in a google document. I am receiving the following error:

Exception: action not allowed

I am the owner of all scripts, sheets, and docs involved in this script. I read something about being logged into multiple google accounts causing this issue, but I logged out of my personal google account (this script is with for work account), so that I had only one account active, and the issue persisted.

Here is my code:

function createLetters() {
  //Ids for docs and sheets 
  var docTemplateId = "1PBm3Oghmtf7ZPWolCIY9xGkEyW3l3jR4_3olDDaBvMk";
  var docFinalId = "1fgg_nX-IaN4xOwN7rwey3EX_pGatF136P8GlG0u299w";
  var docFinalId = DocumentApp.create('El Letters').getId();
  var ssID = "1DlWAglK8IJwLtBSH-kUtg3rH6bmuS-MGhl0R7JalM5Q";

  //Get the docs and sheet 
  var docTemplate = DocumentApp.openById(docTemplateId);
  var docFinal = DocumentApp.openById(docFinalId);
  var sheet = SpreadsheetApp.openById(ssID).getSheetByName("ELPA Scores");

  var data = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()).getValues();
  Logger.log(data)
  var templateParagraphs = docTemplate.getBody().getParagraphs();
  
  docFinal.getBody().clear()

  

   for(var i =0;i < data.length;i++){
    createMailMerge(data[i][0],data[i][1],data[i][2],data[i][3],data[i][4],data[i][5],data[i][6],data[i][7],data[i][8],data[i][9],templateParagraphs,docFinal)
  }
}

function createMailMerge(
  firstname,
  lastname,
  school,
  level,
  r,
  w,
  s,
  l,
  status,
  test_date,
  templateParagraphs,
  docFinal){

    templateParagraphs.forEach(function(p){
      docFinal.getBody().appendParagraph(p.copy()
            .replaceText("{{first_name}}", firstname)
            .replaceText('{{last_name}}', lastname)
            .replaceText("{{school}}", school)
            .replaceText("{{level}}",level)
            .replaceText("{{r}}", r)
            .replaceText("{{w}}", w)
            .replaceText("{{s}}", s)
            .replaceText("{{l}}", l)
            .replaceText("{{status}}",status)
            .replaceText("{{test_date}}", test_date)
            //.replaceText("{{contacted_date}}", contacted_date)
          )
        });

      docFinal.getBody().appendPageBreak()
 
}

This feels like a fairly straightforward script, so I'm not sure why I'm encountering this issue. Do I need to incorporate a way to have it get more permissions?

0

There are 0 best solutions below