title: Google Sheets Script - save as PDF - Get Name from Cell
body: <p>Ok, I'm 99% there thanks to a lot of other posts about how to do this. </p>
  
  <p><strong>What am I doing?</strong>
  I have a google form. When that form is completed and the answers are in the respective google sheet I have another tab that has a template (with a bunch of formulas) that auto-populates pay rates for people. The first formula is the name and it is drive off of the Form Responses tab. The following script hides all other sheets, saves the one tab I want to a PDF, in the folder that I want (then unhides the other sheets). </p>
  
  <p><strong>The problem</strong> 
  When I run this as a test it works perfectly. The PDF that drops into the folder is named with the output from the cell E5 (which is a formula) pulling the person's name. However when I set the trigger to when a form answer comes in then everything is right (all the data on the sheet is right) just the name of the file is showing as "Yes". I'm so confused as to why it is "Yes". If I run the script right afterwards it is the name of the person from the cell E5..... Here is my code. </p>
  
  <p>Is the trigger to fast to pull the response? I don't think it can be as the output on the PDF is right. </p>
  
  <hr>
  
  <pre><code>function topdf() {
    var foldersave=DriveApp.getFolderById('1dSOK6bBCRyEO0_fTuuMFH9sNa4wAWYW8');
    var d= new Date();
  
  
    var request = {
      "method": "GET",
      "headers":{"Authorization": "Bearer "+ScriptApp.getOAuthToken()},    
      "muteHttpExceptions": true
    };
  
    var key='1-e8dhOOZ5zwfeIBSTSH7yFNKgxVTxwqZvqcTNtQUQrA'; 
    var fetch='https://docs.google.com/spreadsheets/d/'+key+'/export?format=pdf&amp;size=letter&amp;portrait=false'
    var ss= SpreadsheetApp.getActiveSpreadsheet();
    var sheets=ss.getSheets()
    var name=ss.getRange("E5").getValue()
  
        sheets[0].hideSheet()
        sheets[1].hideSheet()
        sheets[2].hideSheet()
        sheets[3].hideSheet()
        sheets[4].hideSheet()
        sheets[5].hideSheet()
        sheets[6].hideSheet()
  
    var pdf = UrlFetchApp.fetch(fetch, request);
    pdf = pdf.getBlob().setName(name);
    var file = foldersave.createFile(pdf)
  
        sheets[0].showSheet()
        sheets[1].showSheet()
        sheets[2].showSheet()
        sheets[3].showSheet()
        sheets[4].showSheet()
        sheets[5].showSheet()
        sheets[6].showSheet()
  }
  </code></pre>