Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the ID of the apps script inside a spreadsheet

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 ?

like image 584
seba123neo Avatar asked May 13 '16 13:05

seba123neo


People also ask

How do I find the id of a spreadsheet?

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".


2 Answers

Although this is an old post, hopefully this is useful for anyone looking:

var scriptID = ScriptApp.getScriptId();

Source: Google Apps Script Services API

like image 150
Mycah Avatar answered Oct 26 '22 11:10

Mycah


I had a similar problem. I solved it by doing the following;

IN THE SHEET THAT IS BEING COPIED

  1. add a function to the sheet's script with the following code: function ScriptID(){return ScriptApp.getScriptId()}

  2. In some cell add the formula =ScriptID()

  3. 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

like image 37
Tyler Massey Avatar answered Oct 26 '22 11:10

Tyler Massey