Lucas Borges
Lucas Borges

Reputation: 23

How to get the domain in a variable?

I'm running multiple codes with different domains. I do not want to put the domain manually. For example: var domainName = 'domain.com.br';

I would like to know if it is possible to get the domain (G Suite) through a variable. For example: var domainName = get.domain ();

Upvotes: 0

Views: 172

Answers (1)

Wicket
Wicket

Reputation: 38424

Use Session.getActiveUser().getEmail() / Session.getEffectiveUser().getEmail() to get the active/effective user email address and JavaScript string handling techniques like using regular expressions:

 var domain = Session.getActiveUser().getEmail().match('\@(.*)$')[1]

Validation of regex expression

var match = '[email protected]'.match('\@(.*)$');
console.info(match[1])

Upvotes: 1

Related Questions