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.
Related
This question already has answers here:
Can not run trivial app script bound to new blank document - get "This app is blocked"
(3 answers)
Closed 5 months ago.
I have created a custom function in a Google Sheet and I have given access to the Sheet to other users. But unfortunately the security settings of there company do not allow the users to unlock this script for their account.
This app is blocked. This app has tried to access confidential data in your Google account. To protect your account, we have blocked the access.
Is there any way that users can still run this script externally without having to install it themselves? So for example via a click on a button, which then starts the script in my account.
No, you won't be able to do that. The only way some code could be triggered by external users, but effectively executed by your account, would be in an apps script web app.
As you can see in the screenshot, there's an "Execute as" setting when you deploy an app that controls this behaviour:
I appreciate that this may not be an option for you, given that the current code is a custom function in a sheet. The only other approach would be to have the external users make a copy of the sheet, with its function(s), to run in their Google Workspace environment.
This question already has an answer here:
Getting a list of active file viewers with apps script
(1 answer)
Closed 1 year ago.
So i have a google sheet table to store data of my team (name and gmail account). I will assign every user with different task in my project. I create a web app (user interface) using apps script so my user can interact with the task. In this case, assumes all my users will be using google chrome browser and need to login to the google account on their own browser. For users who use other browser or if not sign in to google account will be ignored.
If i deploy my apps script, is there any method to know which user is browsing it just by checking the google account they use. I don't want to create custom user/pass to login. I just want the script can detect by active google account to personalize the page so they don't need to see all available the task but only can see specific task that they are assigned to.
https://stackoverflow.com/a/66342797/16125139
This should help you
Session.getActiveUser().getEmail()
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:
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 answers here:
Google Apps Script to open a URL
(6 answers)
Closed 2 years ago.
I have a template file in Google Docs. This template is to be copied and the newly created document presented to the user for editing in the browser.
I have a webapp where the user clicks a button and that runs the following code:
var theTemplate = DriveApp.getFileById('[ID_of_the_template');
var theDocument=theTemplate.makeCopy("copy_for_me");
var num=theDocument.getId();
Logger.log(num);
This makes the copy and then in the variable "num" I have the document ID I need and all I now need is to open a link to
https://docs.google.com/document/d/[docuID_here]/edit
but I can find no way to do so.
I am sure this is easy but I can not find how to do it. Maybe I am thinking too complicated or am on the wrong track.
As always I appreciate any and all help.
Greetings from the Bavarian Alps.
See the accepted answer here. I do not believe this has changed in the past 3 years. Basically, the portion of the script which creates the file is run on the server.
That said, IF your web app has a client side, you may be able to return the file link back to the client side and display it as a link for the user to open.