title: Declaring a variable stops the function in apps script
body: <p>I'm creating a projects database using google sheets and Apps Script.</p>
  <p>I have developed the code below to add a new record page (sheet) every time a new record/project is added to the projects list sheet.</p>
  <p>The strange thing is that the code works well but when I declare the variable <code>text</code> in line 11 the code doesn't work. Actually, the variable <code>text</code> is not even used in the code yet. it doesn't contribute to the code's logic.</p>
  <p>Can anyone explain this to me, please?</p>
  <pre><code>// This module is to add a new project record page when a new project included in the Project List sheet
  
  function addNewRecord(e){
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheetName = ss.getActiveSheet().getSheetName();
    var sheet = e.source.getSheetByName(&quot;Template&quot;);
    var row = e.range.getRow();
    var col = e.range.getColumn();
    var cell = e.source.getActiveSheet().getRange(row,1).getValue();
    var text = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Projects List').getRange(row,1).getCell(row,1);
  
    var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();  //creating an array or calling the existing sheets of the spreadsheet.
  
    var sheetsNames = [];        //creating an array of the existing sheets names
  
    for (let i =0 ; i &lt; sheets.length; i++){
        
      sheetsNames[i] = sheets[i].getSheetName();
  
    }
  
  
    //checking the entered value contains LCE keyword and it's an actual new record
    if (sheetName === 'Projects List' &amp;&amp; col ===1){
      
      if (cell.includes('LCE') &amp;&amp; sheetsNames.indexOf(cell) === -1){
  
        sheet.copyTo(ss).setName(cell);
        ss.getSheetByName(cell).getRange(1,2).setValue(cell);
        
        function getSheetUrl() {
          var SS = SpreadsheetApp.getActiveSpreadsheet();
          var ss = SS.getSheetByName(cell);
          var url = '';
          url += SS.getUrl();
          url += '#gid=';
          url += ss.getSheetId();
          //Logger.log(url); 
          return url;
        }
  
        var value = SpreadsheetApp.newRichTextValue().setText(cell).setLinkUrl(getSheetUrl()).build();
  
        //e.source.getSheetByName('Projects List').getRange(row,1).getCell(row,1).setRichTextValue(value);
  
        //cellV.setRichTextValue(value);
        
      }
    }
  //Logger.log(sheets);
  }
  </code></pre>