- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 07:10 AM
Hello Developers,
I am trying to retrieve the sysid from some user generated events from the syslog table. Get the message from the syslog table, slice the string and only return the value I need which is the sysid value. Use the sysid values and query it in the sys_user table to retrieve the displayvalues.
I am getting the results I want from the first query but the second query is fetching all the data from the sys_user table which I don't want. I just want to pass the results from the first query and iterate through result. I think the second query does not know about the variable from the first query. How can I achieve this?
grlog = new GlideRecord('syslog');
grlog.addEncodedQuery("customcopiedquery");
grlog.query(); //query to go through the logs table.
while(grlog.next()){
var messages = grlog.message;
var msgstr = messages.toString();
var sysid = msgstr.slice(57,89); //slice the string and only return what I need.
gs.print(sysid); //I am able to get the proper string value I need by verifying the output.
grSys = new GlideRecord('sys_user');
grSys.addquery('sys_id',sysid); //query the sys_id and the value from the first query. this is not working.
grSys.query();
while(grSys.next()){
gs.print(grSys.uniqueValue);
gs.print(grSys.first_name);
gs.print(gr.Sys.last_name);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 07:20 AM
is sysid a single value or comma separated?
If its a single value, can you try sysid.toString()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 07:50 AM - edited 11-18-2022 07:52 AM
Like Mike said, you can use sysid.toString() and change the 'while' to 'if'.
Also there are couple of typos/syntax errors. (addquery, uniqueValue)
Fixing all these, your second function can be:
grSys = new GlideRecord('sys_user');
grSys.addQuery('sys_id',sysid.toString()); //query the sys_id and the value from the first query. this is not working.
grSys.query();
if(grSys.next()){
gs.print(grSys.getUniqueValue());
gs.print(grSys.first_name);
gs.print(grSys.last_name);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 07:20 AM
is sysid a single value or comma separated?
If its a single value, can you try sysid.toString()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 07:50 AM - edited 11-18-2022 07:52 AM
Like Mike said, you can use sysid.toString() and change the 'while' to 'if'.
Also there are couple of typos/syntax errors. (addquery, uniqueValue)
Fixing all these, your second function can be:
grSys = new GlideRecord('sys_user');
grSys.addQuery('sys_id',sysid.toString()); //query the sys_id and the value from the first query. this is not working.
grSys.query();
if(grSys.next()){
gs.print(grSys.getUniqueValue());
gs.print(grSys.first_name);
gs.print(grSys.last_name);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 11:18 AM
Thank you @mdash and @Mike_R for the help! I am new to all of this.
Now I will try to add this to an action step in Flow Designer.
var sysarray = [];
grlog = new GlideRecord('syslog');
grlog.addEncodedQuery("customcopiedquery;
grlog.query();
while(grlog.next()){
var messages = grlog.message;
var msgstr = messages.toString();
var sysid = msgstr.slice(57,89);
sysarray.push(sysid.toString());
}
for (var i =0; i <sysarray.length; i++){
var user = sysarray[i];
grSys = new GlideRecord('sys_user');
grSys.addQuery('sys_id',user.toString()); //query the sys_id and the value from the first query. this is not working.
grSys.query();
if(grSys.next()){
gs.print(grSys.getUniqueValue());
gs.print(grSys.first_name);
gs.print(grSys.last_name);
}}