- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 01:18 PM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 01:55 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 01:55 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 03:04 PM - edited ‎01-22-2024 03:16 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 04:20 PM
Hi Raj the only payload I can get out of this is [object GlideRecord]. I have tried dot walking & getRefRecord.
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 09:36 PM
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.