How to get the sys_id using glide record

Jeni Sebastian
Mega Contributor

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();
}

 

11 REPLIES 11

Hi,

is u_user a reference field to sys_user?

if yes then it would work fine

Regards
Ankur

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

u_user field is not referenced to sys_user . It is a string field

Hi,

then if you wish to store user name then do this

var gr = new GlideRecord('custom table 1');
gr.addEncodedQuery('nameSTARTSWITHJ');
gr.query();
if(gr.next()){

    var upd = gr.u_apprentice_eid.user_name; // 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

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

@Jeni Sebastian 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

Can we update the metric result to fields in incident table?