- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 04:15 AM
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.
Thank you,
Shreya Sinha
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 04:28 AM - edited 09-04-2023 04:29 AM
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....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 04:28 AM - edited 09-04-2023 04:29 AM
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....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:06 AM
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 );
}