title: Google Scripts Error: "You do not have permission to call sort"
body: <p>I am trying to run a custom function within Google Sheets. I do not get a compile error but when I try to call the function, I get an #ERROR along with a message,</p>
  
  <blockquote>
    <p>You do not have permission to call sort</p>
  </blockquote>
  
  <p>Is there a way to get around this problem? How can I sort a range within a custom function if <code>range.sort</code> is not available? </p>
  
  <p>Here is my code:</p>
  
  <pre><code>function installmentPrice(priceRange, measuringPeriod, lowestDays,     discount) 
  {
      measuringPeriod = measuringPeriod || 5;
      lowestDays = lowestDays || 1;
      discount = discount || 1;
  
      var sheet = SpreadsheetApp.getActiveSpreadsheet();
      var tempRange = sheet.getRange("C3:C9");
  
      var newRange = tempRange.offset(0,0,measuringPeriod);
      newRange.sort(newRange.getColumn());
  
      Logger.log(newRange.getValues());
  
      var lowestSum = 0;
      var installmentPx = 0;
  
      for (i=0; i&lt;= lowestDays; i++) {
          lowestSum = lowestSum + newRange[i];
      }
  
      lowestSum = lowestSum/lowestDays;
      installmentPx = discount * lowestSum;
      return installmentPx;
  
  }
  </code></pre>