Using STARTSWITH operator in Business Rule scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2017 07:10 AM
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.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2017 11:41 AM
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");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2017 11:44 AM
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");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2017 12:06 PM
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) {