Need to fetch the userid from the field

Shreya Sinha1
Tera Contributor

Hi All,

 

I have a requirement to fetch the userid(highlighted one) from the "Name" field and to check in sys_user table and to take the full name from the user table.

 

ShreyaSinha1_0-1693826568952.pngShreyaSinha1_1-1693826603471.png

 

 

Thank you,

Shreya Sinha

1 ACCEPTED SOLUTION

Sohail Khilji
Kilo Patron

Hi @Shreya Sinha1 ,

 

You can use the below idea to get the value and search in sys_user to get the fullname.

 

var name = current.variables.name.toString();

var split_name = name.split('|');
var user_id = split_name[1];
gs.print(user_id);
 
var find_user = new GlideRecord('sys_user');
find_user.addQuery('user_name', user_id );
find_user.query();
if(find_user.next()){
var fullname = find_user.first_name + " " + find_user.last_name;
gs.info(' the found user name is '+fullname );
 }
 

 

I hope this help ! Please use the above code and adjust it were ever needed !

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

View solution in original post

2 REPLIES 2

Sohail Khilji
Kilo Patron

Hi @Shreya Sinha1 ,

 

You can use the below idea to get the value and search in sys_user to get the fullname.

 

var name = current.variables.name.toString();

var split_name = name.split('|');
var user_id = split_name[1];
gs.print(user_id);
 
var find_user = new GlideRecord('sys_user');
find_user.addQuery('user_name', user_id );
find_user.query();
if(find_user.next()){
var fullname = find_user.first_name + " " + find_user.last_name;
gs.info(' the found user name is '+fullname );
 }
 

 

I hope this help ! Please use the above code and adjust it were ever needed !

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hi Sohail,

 

Thank you for your response.

Information is not printing inside if loop.The code is not going to If loop thats why I'm not able to fetch the full name.

 

code-

var name = 'abcd, efgh | abcd';

var split_name = name.split('|');
var user_id = split_name[1];


var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', user_id );
gr.query();
//gs.print(user_id);

if(gr.next()){
gs.print(user_id);
gs.print("testing" +gr.user_name);
var fullname = gr.first_name + " " + gr.last_name;
gs.print(' the found user name is '+fullname );
}