Solved

Google  (Get  Users Email)

Posted on 2016-10-19
2
100 Views
Last Modified: 2016-10-20
The script run I have will get a timestamp of when a row is edited and puts the user in the comments box at the end of the row of cells.  cannot get the script to run and get the email of the current person editing the google sheet.  It will only return the email of the Admin/Owner of the script, or it will just retune a blank value.  

I have run even combination I can think of using like getEffectiveUser, getActiveUser and so on.

function myFunction() {
  
}
function onEdit(event){
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  //Script Last Update Timing

  var actSht = event.source.getActiveSheet();
  var actRng = event.source.getActiveRange();

  var activeCell = actSht.getActiveCell();
  var row = activeCell.getRow();
  var column = activeCell.getColumn();

  if(row < 4)   return; //If header row then return
  var colNums  = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]; //Coulmns, whose edit is considered
  if(colNums.indexOf(column) == -1) return; //If column other than considered then return


  var index = actRng.getRowIndex();
  var dateCol = actSht.getLastColumn();
  var lastCell = actSht.getRange(index,dateCol);
                  var date = Utilities.formatDate(new Date(), "PST", "MM/dd/yy HH:mm");


   // Log the email address of all users who have edit access to a file. 
  var email = Session.getActiveUser().getEmail();
 Logger.log(email);
  
  // Note: Insert the Date when someone update the row in the last coulmn
  lastCell.setValue(date).setComment(email);


}
 

Open in new window

0
Comment
Question by:Joshua Joseph
2 Comments
 
LVL 12

Accepted Solution

by:
Koen Van Wielink earned 500 total points
ID: 41851560
It might not be possible to extract this information. From Google's help pages:

Gets information about the current user. If security policies do not allow access to the user's identity, User.getEmail() returns a blank string. The circumstances in which the email address is available vary: for example, the user's email address is not available in any context that allows a script to run without that user's authorization, like a simple onOpen(e) or onEdit(e) trigger, a custom function in Google Sheets, or a web app deployed to "execute as me" (that is, authorized by the developer instead of the user). However, these restrictions generally do not apply if the developer and the user belong to the same Google Apps for Business domain.

Document can be found here.
0
 

Author Closing Comment

by:Joshua Joseph
ID: 41852190
Thanks you,
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript create file issue 4 48
jQuery AJAX Redirects Without Response/Error 10 46
Change javascript css 1 20
Window.Open() is showing a blank page 9 16
Whether you’re looking to gather data for research or gather feedback on an idea, being able to build and distribute your own online survey is not only cost-effective, but allows you to reach a larger audience and receive results in real-time. Googl…
Google is more than just a search engine. Over the years the company has developed a wide range of online services that are readily available to all users. This article highlights how one can use Google services for simple project management.
This Micro Tutorial demonstrates in Google Analytics how to create a custom report that shows you traffic over time using the month of year dimensions. There are also instructions on how to fix Google's odd month of year formatting, which Microsoft …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now