How to get the sys_id using glide record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 10:00 PM
Hello everyone!
I would like to know how to get the sys_id of the user using gliderecord because i tried to get the value of the sys_id but its not showing the value in "notifs.u_user".
Below, Im creating new records in custom table 2 and I need to set the "notifs.u_user" value to the sys_id of the user that is in the custom table 1.
Here's what I did :
var gr = new GlideRecord('custom table 1');
gr.addEncodedQuery('nameSTARTSWITHJ');
gr.query();
var upd = gr.u_apprentice_eid.getValue('sys_id'); // in this line I tried to get the sys_id of the user
if(gr.next()){
var notifs = new GlideRecord('custom table 2');
notifs.initialize();
notifs.u_send_date = '2022-08-26';
notifs.u_user = upd;
notifs.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 10:04 PM
Hi,
You can get sysid using
var gr = new GlideRecord('incident');
gr.addQuery(number, 'INCXxx');
gr.query();
if(gr.next()){
var usysid = gr.getUniqueValue();//will fetch sysid
}
you can use var upd = gr.u_apprentice_eid.getUniqueValue();
Please mark my answer correct/helpful if it helped u in anyway
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 10:16 PM
Hi ! thanks @Gayathri . I tried this one but it still doesnt work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 10:05 PM
Hi,
try to update as this
1) put the line inside if
2) if field "u_apprentice_eid" is reference to user then don't dot walk to get sysId
var gr = new GlideRecord('custom table 1');
gr.addEncodedQuery('nameSTARTSWITHJ');
gr.query();
if(gr.next()){
var upd = gr.u_apprentice_eid; // in this line I tried to get the sys_id of the user
var notifs = new GlideRecord('custom table 2');
notifs.initialize();
notifs.u_send_date = '2022-08-26';
notifs.u_user = upd;
notifs.insert();
}
Regards
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
06-08-2022 10:18 PM
Hi
Yes the field is reference to sys_user . I tried this one but still it doesnt show the user in notifs.u_user.