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()

It logs something like this:

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

>Solution :

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

Modified script:

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


Leave a ReplyCancel reply