Find sys_id of user record when only data available is a string field with user_name

Lon Landry4
Mega Sage

For use case reasons a string field is required to capture user data.

I need to find sys_id of user record when only data available is a string field with user_name.

I was hoping to accomplish this task as simply as possible, so a Script Includes/Client script is not the direction I want to go in...

 

I am trying the below script in workflow but the query result is "undefined".

var rqstdFor = current.variables.someUser;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name',rqstdFor);
userGR.query();
var testThis = userGR.query();
gs.addInfoMessage(testThis);

1 ACCEPTED SOLUTION

raj149
Giga Guru

Hello @Lon Landry4 

 

Use below script 

var rqstdFor = current.variables.YOUR VARIABLE NAME; 
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id',rqstdFor);
userGR.query();

if (userGR.next()) {

 

gs.info('username is :' + userGR.user_name) //replace the field name as per your requirement

}

 

 

1.open 'syslog' table.

2.Search with this filter condition ' message contains username is : ' then you can see rqstdFor user_name.

View solution in original post

5 REPLIES 5

Lon Landry4
Mega Sage

This got me going in the right direction, I still needed to add gr.getValue('sys_id').

But in error I was trying gr.getValue.sys_id