Using STARTSWITH operator in Business Rule scripting

akalya
Kilo Explorer

Hi, i have the below script written for after insert business rule. The if condition checks are not working as expected.

if(current.u_message, 'STARTSWITH', "The filesystem \"/var\"   is full")

{

gs.addInfoMessage("file system");

grInc.setValue("assignment_group",'80420dc6fcaa540b9649aad5d3ee4fe');

grInc.setValue("impact","3");

grInc.setValue("urgency","3");

grInc.setValue("priority","3");

}

if(current.u_message, 'STARTSWITH', "Alert Title: Qtree Full")

{

gs.addInfoMessage("qtree");

grInc.setValue("assignment_group",'0e420d0c6fcaa540b9649aad5d3ee4bf');

grInc.setValue("impact","3");

grInc.setValue("urgency","3");

grInc.setValue("priority","3");

}

else if(current.u_message,'STARTSWITH','Alert Title: Disks: Some Failed')

{

gs.addInfoMessage("disk fail");

grInc.setValue("assignment_group",'1483b53f6fa95180b9649aad5d3ee4fd');

grInc.setValue("impact","4");

grInc.setValue("urgency","4");

grInc.setValue("priority","4");

}

when executing I'm setting message field to "Alert Title: Qtree Full" but the first if condition evaluates to true and i'm getting the info message as "file system".

Can anyone please let me know the issue with the scripting written. I tried using the "==" operator instead of "STARTSWITH" and that works fine. So there must be some syntax errors in processing string values with STARTSWITH operator.

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Akalya,



Try



if(current.u_message.startsWith("The filesystem \"/var\"   is full")) and   check once.


Final script will be.


if(current.u_message.startsWith("The filesystem \"/var\"   is full"))  


{  


gs.addInfoMessage("file system");  


grInc.setValue("assignment_group",'80420dc6fcaa540b9649aad5d3ee4fe');  


grInc.setValue("impact","3");  


grInc.setValue("urgency","3");  


grInc.setValue("priority","3");  


}  


if(current.u_message.startsWith("Alert Title: Qtree Full"))  


{  


gs.addInfoMessage("qtree");  


grInc.setValue("assignment_group",'0e420d0c6fcaa540b9649aad5d3ee4bf');  


grInc.setValue("impact","3");  


grInc.setValue("urgency","3");  


grInc.setValue("priority","3");  


}  


if(current.u_message.startsWith('Alert Title: Disks: Some Failed'))  


{  


gs.addInfoMessage("disk fail");  


grInc.setValue("assignment_group",'1483b53f6fa95180b9649aad5d3ee4fd');  


grInc.setValue("impact","4");  


grInc.setValue("urgency","4");  


grInc.setValue("priority","4");  


}  






DilipKumar DJ
Kilo Guru

Hi Akalya,



Use this:



var str = current.u_message;


if(str.startsWith("The filesystem \"/var\"   is full"))


{


gs.addInfoMessage("file system");


grInc.setValue("assignment_group",'80420dc6fcaa540b9649aad5d3ee4fe');


grInc.setValue("impact","3");


grInc.setValue("urgency","3");


grInc.setValue("priority","3");


}


if(str.startsWith("Alert Title: Qtree Full"))


{


gs.addInfoMessage("qtree");


grInc.setValue("assignment_group",'0e420d0c6fcaa540b9649aad5d3ee4bf');


grInc.setValue("impact","3");


grInc.setValue("urgency","3");


grInc.setValue("priority","3");


}


if(str.startsWith('Alert Title: Disks: Some Failed'))


{


gs.addInfoMessage("disk fail");


grInc.setValue("assignment_group",'1483b53f6fa95180b9649aad5d3ee4fd');


grInc.setValue("impact","4");


grInc.setValue("urgency","4");


grInc.setValue("priority","4");


}


Chuck Tomasi
Tera Patron

You could also just use the standard Javascript method indexOf() to get the position of that string.



var str = current.getValue('u_message');


if (str.indexOf("The filesystem \"/var\"   is full") == 0) {