This question already has answers here:
Do Google Apps scripts permit any sort of introspection?
(2 answers)
Closed 5 months ago.
Can a Google Apps Script determine its own resource id? If it could, then it could discover what folders it is in (parents).
If it is only in one folder, then it could use that folder as a default folder for various purposes.
If it is in multiple folders, then the resource id is insufficient to truly identify where the script was started from, so the corollary question is can a Google apps script determine the resource id of the folder it was launched from?
Seems like these would be useful additions, maybe to Class Session, if it doesn't already exist somewhere that I have missed.
For a Spreadsheet I found this to work:
var thisFileId = SpreadsheetApp.getActive().getId();
var thisFile = DocsList.getFileById(thisfileId);
As per my knowledge, there is no option in Google Apps Script to get its own resource ID. You should file a feature request in Google Apps Script Issue tracker.
Related
This question already has answers here:
What is the appropriate way to manage API secrets within a Google Apps script?
(2 answers)
How to protect the Apps Script code in a Google spreadsheet?
(6 answers)
button click is only working on Windows & not working on Android mobile sheet
(2 answers)
Closed 6 months ago.
The Apps Script attached to the Sheet has a function that is meant to be called by any of the collaborators.
But the Apps Script source contains a secret key. So my collaborators should not have read access to the script, just execute access.
Is this not possible? Thank you.
If you share a Sheet with the App Script:
( and you want other users to be able to edit the Sheet)
it is not possible to keep the code hidden.
To do that you need to publish the Script as an add-on on Google Workspace Marketplace.
Please find more information on How to publish App Script Add-on
The general question has already been answered here
This question already has answers here:
Google apps script drive file: How to get user who last modified file?
(2 answers)
Closed 2 years ago.
I am a beginner in Google App Script. I want to fill a sheet with a google app script. For that I need to get the appropriate information. But I do not get the email address from the last modifying user. May you help what I can do to get the email address from the user who was the last one who modified the file? If I try the following code I get the error message:
GoogleJsonResponseException: API call to drive.files.get failed with error: File not found: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
listFilesInFolder # Code.gs:70
The xxx are just placeholder for the appropriate fileID. (This is working!)
Thank you very much in advance!
var fileID = file.getId();
lastmodifier = Drive.Files.get(fileID).lastModifyingUser.emailAddress;
Your code doesn't contain part how do you get the file object.
Only after reading your title I assume you used the DriveApp.
For the last lastModifyingUser you should use Drive, not the DriveApp. Maybe that is the cause of your code break. You should use:
Drive.Files.get('<FILEDID>').lastModifyingUser
But first you have to enable Drive API in your project.
DriveApp is something like out of the box, for the most common tasks, Drive is more powerful, something like the next level, but you have to include it explicitly.
You have an answer to your question on this SO post
Google apps script drive file: How to get user who last modified file?
together with the explanation how to enable Drive API.
Since you have the file object already, it should already have the email of the last modifying user. You can reference it using:
file.lastModifyingUser.emailAddress
References:
Google Drive API | Files
This question already has answers here:
Share a Drive document without notifying user with Google Apps Script
(3 answers)
Closed 5 years ago.
I have a google-appmaker project where I add the list of possible viewers down the workflow chain to a file. Once the user attaches a file and starts the workflow, I take the attached file and the viewers down the chain to it so that they can view it.
However when I use it, it also sends another email to the user, and the viewers that the file is shared. Ideally I'd like to add them without triggering the email since there is also another email that goes when the workflow starts. Is there a way to add viewers without notifying them file.addViewers doc.
Thanks
This can be done using the advanced Drive API.
Documentation is here
and code goes like this :
function testFileSharing() {
shareFile("14fQ#################9SW2SIIutz5qk");
}
function shareFile(ID){
var permission = Drive.Permissions.insert({value:"test#gmail.com",role:"reader",type:"user"},ID,{sendNotificationEmails:false,emailMessage:"testing for you"});
Logger.log(JSON.stringify(permission));
}
The advanced Drive API must be enabled in the ressources menu and in the Google API Console.
This question already has answers here:
How to protect the Apps Script code in a Google spreadsheet?
(6 answers)
Closed 5 years ago.
I have ID key of the master script and I have did connecting it to another users spreadsheet template as a Library but what I want to do is How to make the spreadsheet template access to the master script being limited or should be not shared.
When I'm going to deleted a master script even the library still appears on the list of clien script of the spreadsheet template but all function seperate dead completely or it has said like this:
YOU DO NOT HAVE ACCESS TO LIBRARY *******, USED BY YOUR SCRIPT, OR IT HAS BEEN DELETED.
Try coment from #user3887038 in Q16075446. It make possible to hide library code, but it made difficult to updating code
This question already has an answer here:
publish a Google Spreadsheet through Google Apps Scripts
(1 answer)
Closed 3 months ago.
Is there any plan to provide Google Apps Script capability for the "Files | Publish to the web..." menu item in a Google Document?
This has been asked before, but heck if I can find an answer. To be clear, I don't mean setting the sharing or viewability of the Document itself, I mean the thing where a web page representation of the Document with its own link is generated.
There is now a method for this, provided here.
First, add the service Drive API
var docId = "###"; // Please set this.
Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, docId, 1);
It is not possible directly with GAS. However, using the Document List API and URLFetch with oAuth, you can, in theory make a document public on the web. Publish to the web option, per se, isn't available though.
Please see the following links for information and help
How do I get an access token using UrlFetchApp with GAS
https://developers.google.com/google-apps/documents-list/#sharing_resources_with_the_public_the_rest_of_the_internet