Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract a username from an email address using Google App Script

I’m using the following script to get the user’s email address:

  function getEmail() {
  var userEmail = Session.getActiveUser().getEmail()
  Logger.log(userEmail);
  }

It logs something like this: username@domain.com

I’d like to extract the username (everything to the left of @) and log it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

About It logs something like this: username@domain.com, when your showing script is run, you can see username@domain.com in the log. And, you want to retrieve username from username@domain.com, how about the following modification?

Modified script:

function getEmail() {
  var userName = Session.getActiveUser().getEmail().split("@")[0];
  Logger.log(userName);
}

Reference:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading