How to use Sheets Advanced Service in Google App Script

306 views
Skip to first unread message

Tuan Do

unread,
Nov 30, 2021, 5:42:00 PM11/30/21
to Google Apps Script Community
I am trying to use `batchUpdate` in Google App Script. I found this example link which shows me how to do it. However, when I use it in my normal Google App Script, it says `ReferenceError: Sheets is not defined`. I wonder how I can use Sheets Advanced Service in Google App Script so that I can use `batchUpdate`.

Thanks a lot

cbmserv...@gmail.com

unread,
Nov 30, 2021, 6:38:17 PM11/30/21
to google-apps-sc...@googlegroups.com

Share your code if you want us to identify what you may have done wrong.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/39a04df8-3979-4e11-9256-91c2bf189f05n%40googlegroups.com.

Tuan Do

unread,
Nov 30, 2021, 7:54:49 PM11/30/21
to Google Apps Script Community
I just use code in the example in that link.

````
function changeTitle(){
     var updateSpreadsheetPropertiesRequest = Sheets.newUpdateSpreadsheetPropertiesRequest();
     updateSpreadsheetPropertiesRequest.properties = Sheets.newSpreadsheetProperties();
     updateSpreadsheetPropertiesRequest.properties.title = title;
     updateSpreadsheetPropertiesRequest.fields = 'title';

}
`````
The error is ReferenceError: Sheets is not defined

CBMServices Web

unread,
Nov 30, 2021, 8:07:51 PM11/30/21
to google-apps-sc...@googlegroups.com
If this is all of your code, then sheets is not defined. You need to declare it before using it.

Am sure the example has that defined. So make sure you copy over all of the code.


David Tew

unread,
Nov 30, 2021, 8:16:16 PM11/30/21
to google-apps-sc...@googlegroups.com
Perhaps you have not yet enabled Advanced Services for Sheets . See here 

--
Regards
David Tew
01522 704293


Tuan Do

unread,
Nov 30, 2021, 8:27:39 PM11/30/21
to Google Apps Script Community
Thank you David, everything works now. A quick follow up question if you don't mind: I am developing an add-on (to be published on Google Workspace Marketplace) for other users to use. I am just curious whether they will also need to enable Sheets API to fully use my add-on? Thanks

David Tew

unread,
Nov 30, 2021, 8:34:28 PM11/30/21
to google-apps-sc...@googlegroups.com
I don’t know this answer since I’ve never made an add-on.  Bruce and others will know - hopefully someone’s around here soon. I’d like to know too, as it goes.

Andrew Roberts

unread,
Dec 1, 2021, 1:52:23 AM12/1/21
to google-apps-sc...@googlegroups.com
There is only one script project associated with an Add-on, and as you have enabled the Advanced service in that any users of the Add-on won't have to enable it too.

David Tew

unread,
Dec 1, 2021, 3:18:06 AM12/1/21
to google-apps-sc...@googlegroups.com

Tuan Do

unread,
Dec 1, 2021, 6:56:51 AM12/1/21
to Google Apps Script Community
Thank you Andrew
Reply all
Reply to author
Forward
0 new messages