Getting UserID and Full Name from email address

DanielCordick
Mega Patron
Mega Patron

I am receiving an inbound action that contains a user email address, How do i then query the user table for the Users Full name and User ID based on just the email address?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

sample script below

var userRecord = new GlideRecord('sys_user');
userRecord.addQuery('email', email.from.toString());
userRecord.query();
if(userRecord.next()){
var userName = userRecord.user_name;
var fullName = userRecord.name;
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Anil Lande
Kilo Patron

You can use GlideRecord query to get user record based on email.

 

 

var userGR = new GlideRecord('sys_user');

userGR.addQuery('email','email address from inbound email');  //email.origemail

userGR.query();

if(userGR.next()){

var user_id = userGR.user_name;

var user_f_name = userGR.name;

}

 

 

Please mark helpful/correct answer if this resolves your issue.

 

Thanks,

Anil

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

sample script below

var userRecord = new GlideRecord('sys_user');
userRecord.addQuery('email', email.from.toString());
userRecord.query();
if(userRecord.next()){
var userName = userRecord.user_name;
var fullName = userRecord.name;
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader