- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 04:30 PM
Hi, I think I need another eye to check my script. I've tried this in the background script, but it does not return a value.
What could be the issue on the subjectRoom attribute that's failing the query condition?
subj = "[Alert] London 101 is down";
var zRoom = subj.toString().split('[Alert] '); //split the subject
var subjectRoom = zRoom[1];
gs.info(subjectRoom.toString());
var grRoom = new GlideRecord('cmdb_ci_iot');
grRoom.addQuery('name','STARTSWITH',subjectRoom);
grRoom.query();
while(grRoom.next())
{
gs.log(grRoom.support_group.getDisplayValue());
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 01:37 PM
This results after adding a few more lines to return only the first word after Alert.
subj = "[Alert] London 101 is down";
var array = subj.split(" ");
var alrt = array[0];
var subjectRoom = array[1];
for(var i=1;i<alrt.length;i++){
array[i];
}
gs.print(array[1])
var grRoom = new GlideRecord('cmdb_ci_iot');
grRoom.addQuery('name','STARTSWITH',subjectRoom[0]);
grRoom.query();
if(grRoom.next())
{
gs.print(grRoom.support_group.getDisplayValue());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 12:09 AM
Hi @olufsen ,
You split the subject in a way your room name should start with 'London 101 is down', where I suspect you like to have 'London'.
If you split the string on a space, you get only London : var zRoom = subj.toString().split(' '); //split the subject
Regards,
Hayo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 01:29 PM
Thanks Hayo, I should have split it further to only return London.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 04:45 AM
I'm running this as a Fix Script with gs.print lines for simplicity. Without changing anything, I'm getting subjectRoom = 'London 101 is down'. I created 2 records on my IOT table with the names 'London 101 is down' and 'London 101 is down today'. The second log/print line is showing me the names of the support group for each record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 01:30 PM
I need to trim down the result to only take London instead of the whole line.