How get email address of active normal user on spreadsheet in the App script

3,813 views
Skip to first unread message

Omkar Deshpande

unread,
May 19, 2022, 2:21:29 AM5/19/22
to Google Apps Script Community
Hey,

Here is the scenario,

I am building a google spreadsheet to document all the tasks for various sheet users and each user can access only his/her cells. For this, I think I need to first get the email address of active user (not App script user, a simple normal user) but I could not find how to get it.

I tried using 

var email = Session.getActiveUser().getEmail();

It gets me the email address of the person who is running the script and not the one who is normal user not running script.

Anyone know how to get around this?

Thanks you so much in advance,
Omkar Deshpande

Martin Molloy

unread,
May 19, 2022, 3:55:29 AM5/19/22
to google-apps-sc...@googlegroups.com

var email = Session.getEffectiveUser().getEmail();



--
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/2f24fb7c-3a96-4834-b91f-738c0830e3c3n%40googlegroups.com.

Getnet Demil

unread,
May 19, 2022, 7:57:53 AM5/19/22
to Google Apps Script Community
Greetings
hello, I have created a google sheet of 6 users shared in editor 
permission to the sheet. each user input their own data and they only can modify it later.
But I want to restrict other users from modifying other's data in google Sheets?
I don't want others can change someone data

so if anyone with the app script code to restrict modifying  others data, please help me?????????

I want to restrict within the same sheet 
when someone types for the first time 
the system will automatically identify him 
and will only allow him to modify. 

Jonathan Butler

unread,
May 19, 2022, 9:44:37 AM5/19/22
to google-apps-sc...@googlegroups.com
I can break it down for you. First, I think you would probably be better suited using a Google form with the setting allowing people to edit their responses. Then you can use formulas to move the data to a different tab created for each of them. 

If the above isn't an option, you would need to install an onEdit(e) trigger for the spreadsheet. Once the onEdit trigger has been triggered check if the sheet name of the range passed in the arguments matches the list of the desired sheets you want to watch. If it is and the sheet isn't already protected, use the above code (prior email) to get the users email. Then you can protect the sheet. The example for the protection is pretty good.


Getnet Demil

unread,
May 20, 2022, 2:08:19 AM5/20/22
to google-apps-sc...@googlegroups.com
google form is not feasible because they will need to follow-up their case therefore if its in google sheet better

You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/JeGnVSSvDwA/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAE9k5yB1N5MQY94wH%3DkpAR6_DeK-6WfvkZUezt3qH4UfH56%3DHQ%40mail.gmail.com.

Martin Molloy

unread,
May 20, 2022, 5:09:48 AM5/20/22
to google-apps-sc...@googlegroups.com
You don't need to use a script you can do this with thebuilt in protection functionality

Go to Data >> protect Sheets and Ranges 

and follow the prompts



Reply all
Reply to author
Forward
0 new messages