Getting user's email from 'sys_user' table.

RajanMurkute
Mega Guru

I am trying to get user's email from GlideRecord.

Here is the code (in Business Rule) -

                gr = new GlideRecord ('sys_user');

                var caller_name = current.caller_id.getDisplayValue();

                gr.addQuery("name", caller_name);

                gr.query();

               if(gr.next){

                      gs.log('1A. Rec Count= '+ gr.getRowCount());

                      gs.log('1AA. gr.email '+ gr.email);

                      }

The log shows as -

 

Table 'sys_user' has 'email' as a valid column name. I don't know why it can't fetch value, but shows 'undefiled as error.

Any suggestion, where I am going wrong?

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

there is issue in your next function; it should be next()

I would recommend querying based on sys_id rather that name; updated code below

use get method to query; it would be somewhat faster I believe rather than addQuery

var gr = new GlideRecord('sys_user');

var caller_name = current.caller_id;

gr.get(caller_name);

gs.log('1A. Rec Count= '+ gr.getRowCount());

gs.log('1AA. gr.email '+ gr.email);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Prateek kumar
Mega Sage

How about the below?

 var gr = new GlideRecord ('sys_user');

 var caller_name = current.caller_id;

 gr.get(caller_name);

gs.log('1A. Rec Count= '+ gr.getRowCount());

gs.log('1AA. gr.email '+ gr.email);

                     

Please mark my response as correct and helpful if it helped solved your question.
-Thanks