Getting user's email from 'sys_user' table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2019 02:32 PM
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 -
Information | 1A. Rec Count= 1 |
Information | 1AA. gr.email undefined |
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?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2019 07:12 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2019 07:41 PM
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