Script Append getting Exception: Action Not Allowed.

368 views
Skip to first unread message

marka...@gmail.com

unread,
Aug 20, 2021, 8:14:03 PM8/20/21
to Google Apps Script Community
 I'm trying to get a script working where several Google Documents are merged into a single document and keep running into  an error with Exception: Action Not Allowed on one of the documents that has 2 inline drawings, which are black bars with white text inside the bars. In the code I have both element types of Inline_Drawing and Inline_Image specified, but it keeps failing. If I remove the inline bars, the script continues on, but fails with the bar drawings inline. And this is not a case where several people are logged into the same account...I'm the only person logged into my account.

  This is a test script I've been playing with trying to get this to work.
This is the error message - Exception: Action not allowed (line 40, file "Code"
Line 40 is this statement: comboBody.appendParagraph(elem);

function listFiles() {

   var fname = 'Mark' ;
   var lname = 'Amezquita' ;
   var sfolder = 'Sellers' ;
   var sheet = SpreadsheetApp.getActiveSheet();
   var folders = DriveApp.getFoldersByName('Masters ' +fname + ' ' +lname); 
   
   if (folders.hasNext())
    folderID = folders.next().getId();
    var dfolder = DriveApp.getFolderById(folderID); 
    
   var contents = dfolder.getFolders();
    
   while(contents.hasNext()) {
    file = contents.next();
    name = file.getName(); 
    if (name == sfolder) {
     var sfid = file.getId();
    var folder = DriveApp.getFolderById(sfid) ;
    var combinedTitle = "Combined Document Example";
    var combo = DocumentApp.create('Combined Seller Docs');
    var comboBody = combo.getBody();
    var files = folder.getFiles();
    while (files.hasNext()) {
      var file = files.next();
      // Print list of files inside the folder
      var src = DocumentApp.openById(file.getId());
      var srcBody = src.getBody();
      var elems = srcBody.getNumChildren();
      for (var i = 0; i < elems; i++ ) {
      elem = srcBody.getChild(i).copy();
      // fire the right method based on elem's type  
      
      switch (elem.getType()) {
        case DocumentApp.ElementType.PARAGRAPH:
          comboBody.appendParagraph(elem);
        break;    
      
       case DocumentApp.ElementType.INLINE_DRAWING:
         comboBody.appendInlineDrawing(elem);
        break;   
         
       case DocumentApp.ElementType.INLINE_IMAGE:
         comboBody.appendInlineImage(elem);  
        break;   
         
       case DocumentApp.ElementType.HORIZONTAL_RULE:
          comboBody.appendHorizontalRule();  
        break;    
          
       case DocumentApp.ElementType.BODY_SECTION:
          comboBody.appendBodySection();   
        break;   
          
       case DocumentApp.ElementType.LIST_ITEM:
          comboBody.appendListItem(elem); 
        break;      
                      
      }
     }
      comboBody.appendPageBreak();
    } 
   }   
  } 
 }
 
  I've attached a sample of the document that it fails on with the Action Not Allowed error. I'm at a loss as to why the failure and any insight would be appreciated. The bars are created by doing a Insert of a Drawing, then adding a text box, filling in  the text inside the box and filling in the colors. So not sure why it's failing when it encounters the bars. This is the first document in the folder but the goal is to append all the documents, 7, into a single doc. The logo and header line appear in the created doc, but that's it and then it fails. If this document is removed from the folder, the script works appending the other documents into one. Thanks.
998 _1 Plan of Action to Sell.docx

Raffi Bilek

unread,
Jan 21, 2023, 11:58:19 PM1/21/23
to Google Apps Script Community
Did you ever solve this? I'm having the same thing.

Ricardo Matias de Carvalho

unread,
Dec 30, 2024, 1:30:56 PM12/30/24
to Google Apps Script Community
I am facing same problem. Any guess?
Reply all
Reply to author
Forward
0 new messages