title: Google Script - DriveApp.getFilesByName - Error (No Permission)
body: <p>I'm trying to call custom function pdfFile from Google Spreadsheets. </p>
  
  <pre><code>function pdfFile(number, revision) {
    // Log the name of every file in the user's Drive.
    Logger.log(number + '_R' + revision + '.pdf');
  
    var files = DriveApp.getFilesByName(number + '_R' + revision + '.pdf');
    while (files.hasNext()) {
      var file = files.next();
      //var name = file.getName();
      var id = file.getId();
      Logger.log(file.getName() + '|' + file.getId());
  
      //Return link to PDF file
      return '=HYPERLINK("https://docs.google.com/file/d/'+id+'/edit?usp=drivesdk";"PDF")';
    }
  }
  </code></pre>
  
  <p>It works when I test it in Script Editor manually.</p>
  
  <pre><code>function test_pdfFile() {
    var range = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getRange("D2:E2");
  
    // Returns cell
    var number = range.getCell(1, 1).getValue();
    var revision = range.getCell(1, 2).getValue();
  
    result = pdfFile(number, revision);
    Logger.log(result);
  }
  </code></pre>
  
  <p>But, when I use custom formula in Spreadsheet, error "You don't have permission to call function DriveApp.getFilesByName (row 5)" comes. I have already switched on Drive API in Resources->Additional Google Functions and in Developer Console. Please, find attached images (sorry, text in Russian). Please, help.</p>