My program works like this:
1 - Make a copy of a public google spreadsheet to my drive account (the account of the user in the device), with the Drive Api, that works fine
2 - the public google spreadsheet has a apps script inside with a simple function, i need to execute that function.
3 - the function in the apps script is executed excelent (with the ID of the script), with the Apps script api from android.
the problem is: each time is performed the copy of the spreadsheet, the script inside changes the ID, i need a way to get that ID always.
How to solve this ?
A spreadsheet ID can be extracted from its URL. For example, the spreadsheet ID in the URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is "abc1234567".
Although this is an old post, hopefully this is useful for anyone looking:
var scriptID = ScriptApp.getScriptId();
Source: Google Apps Script Services API
I had a similar problem. I solved it by doing the following;
IN THE SHEET THAT IS BEING COPIED
add a function to the sheet's script with the following code: function ScriptID(){return ScriptApp.getScriptId()}
In some cell add the formula =ScriptID()
access the value of that cell to retrieve the script ID.
Now, when you copy the original, the function and the formula will be copied with it. In the new sheet, the result of the formula will show the script id for that sheet
WARNING: This may present some security issues since now your sheet's script ID is exposed to anyone with read access to your sheet.
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With