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

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.

Hi Raj,

I tried above code with changed with my field names.

But, no log messages (this part of script fails - userGR = [object GlideRecord]

There is code after this that executes correctly.

Hi Raj the only payload I can get out of this is [object GlideRecord]. I have tried dot walking & getRefRecord.

Any ideas?

Amit Verma
Kilo Patron
Kilo Patron

Hi @Lon Landry4 

 

So you want to get Sys_id of the user when the user record have user name available else do nothing ?

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.