- 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 01:39 PM
If you are sure the city name is right after {alert} - then you can use extra split :
var subjectRoomPre = zRoom[1].split(" ");
var subjectRoom = subjectRoomPre[0];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 05:25 AM
Hi @olufsen ,
I don't see any issue if its name is London 101 is down then it will return the support group name. try with valid record or share what you are looking for?
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 05:59 AM
Firstly, not sure why you use global variable for subj - better put - var subj
Second, for BG script better use print or error instead of log.
Also, try adding something like - gs.error("Record num : " + grRoom.sys_id + "" ); in the while loop - what is the outcome ?
- 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());
}