1

I have a spreadsheet with users, from which I automatically create a new spreadsheet (from a template in my drive) when a new user is created.

I then grant the new user permission to look at the spreadsheet and sent it to him via email.

Here's the question:

In the template I have a field that references another spreadsheet via Importrange("spreadsheeturl"). Now everytime a new spreadsheet is created I need to open the sheet with my account and click on "Allow access" in any of the fields that reference the spreadsheet.

screenshot

Is there anyway to that from my code?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Julian
  • 915
  • 8
  • 24
  • 1
    Possible duplicate of [How can I make an apps script to instantly allow access to all imported elements in a Google Spreadsheet?](https://stackoverflow.com/questions/25178205/how-can-i-make-an-apps-script-to-instantly-allow-access-to-all-imported-elements) – Rubén Jun 15 '19 at 16:43

1 Answers1

0

Good question- I honestly couldn't say. But if the point is just to port data from an existing spreadsheet into this new one, you could use code to replace the importrange.

Something like

var ss = SpreadsheetApp.getActiveSpreadsheet(),
data = openById("string-id"),
value = data.getRange(range).getValue();
ss.getSheetByName("sheet-name").getRange(range).setValue(value);

Hope this helps!

CMena
  • 13
  • 2
  • It needs to be a reference since the value from the original sheet is subject to change. – Julian Jun 14 '16 at 21:01
  • 1
    I see your problem. But importranges are unreliable- I used to use them, but they are extremely prone to throwing errors at random times. You could use the above method, with a trigger to rerun it once a day or so, so that the spreadsheet is kept up-to-date. – CMena Jun 14 '16 at 21:15