Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Script does not return value

olufsen
Kilo Sage

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());
}

 

1 ACCEPTED SOLUTION

olufsen
Kilo Sage

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());
}

 

View solution in original post

8 REPLIES 8

Hayo Lubbers
Kilo Sage

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

Thanks Hayo, I should have split it further to only return London. 

Brad Bowman
Kilo Patron
Kilo Patron

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.  

I need to trim down the result to only take London instead of the whole line.