Run Sheets Add-On as different user

78 views
Skip to first unread message

CSSK Infotech

unread,
Dec 28, 2020, 12:48:09 PM12/28/20
to Google Apps Script Community

Hi Team,


I have two sheets as "Enquiry" and "Master" with owner as "Admin". In enquiry sheet, I protected few columns and shared across users. Users enter data in enquiry sheet and click on Add-on. The plugin will copy data to master sheet and enters some data in locked cells.


Add-on is throwing error because it is not able to edit locked cells. So I want the Add-on to run with Admin account rather than user account or any other way to achieve this solution.


Below is code used in add-on to copy data to master sheet. 

Master_Sheet.getRange(Master_Sheet_lr + 2, 2, user_data_lr, user_data_lc).setValues(user_data);


Thank You very much in advance.


Regards,

Sai Krishna.

Adam Morris

unread,
Dec 28, 2020, 2:57:39 PM12/28/20
to google-apps-sc...@googlegroups.com
Hi there,

The offical way to run a script as a different user is a bit difficult, and requires setting up a service account.

Or you could have the “Admin” owner actually install the add on.

Not sure it’s smart to really go down the rabbit hole of some other workaround, for if an add on does something that is beyond the permissions of the user who installed it, it wouldn’t be great security-wise.

Adam

--
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/bb8308dd-8b13-44b0-bc04-319560f335feo%40googlegroups.com.
--

Alan Wells

unread,
Dec 28, 2020, 3:10:03 PM12/28/20
to Google Apps Script Community
The add-on could make a POST request to an Executable API or Web App that is owned by the Admin
and then the admin code will obviously run with permissions to do whatever it needs to.
But the add-on would need to have permission to make an external request,
which uses UrlFetchApp.fetch(url)
You can publish a Web App or executable API from the same script that is used by the add-on.
Or you could have a separate Apps Script file.
I'm not sure whether one way is better.
Reply all
Reply to author
Forward
0 new messages