cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
678
Views
0
Helpful
5
Replies

Proper format for If statement

Live2 Bicycle
Level 3
Level 3

I have an admin script that based on time of day chagnes Global.user_MH_Nutrition_AftHrsFlag from 1 to 2 to 3.  With my below IF I want to check the caller ID of a number and if it matchs it then checks to see if the Global.user_MH_Nutrition_AftHrsFlag="3".

If all is correct then flow true if not flow false.

left(Call.CallingLineID,6)=="317948"||left(Call.CallingLineID,6)=="317944"||left(Call.CallingLineID,6)=="317274"||left(Call.CallingLineID,6)=="317278"&&Global.user_MH_Nutrition_AftHrsFlag="3"

So currently I am testing from 317948xxxx and Global.user_MH_Nutrition_AftHrsFlag="0".

I am flowing true.  I should not be flowing true.

In my mind I should be flowing false becasue my user variable is passing 0.  I have verified it is passing 0 by watching my schedule admin script.

2 Accepted Solutions

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee

You need to wrap your caller ID conditionals in parenthesis because || and && are short-circuit operators, or lazy evaluators.

Let's shorten it up to two caller ID checks:

if (left(Call.CallingLineID,6) == "317948" || left(Call.CallingLineID,6) == "317944" && Global.user_MH_Nutrition_AftHrsFlag == "3") {

     /* True Block */

} else {

     /* False Block */

}

If we let:

Call.CallingLineID == "317948XXXX"

Global.user_MH_Nutrition_AftHrsFlag == "0"

Then with a little substitution we have:

if (true || false && false) {

     /* This will be true because the first true halts evaluation of the expressions on the right hand side of the || operator */

} else {

     /* False Block */

}

Now if we include parenthesis, using the same substituted values we have:

Step 1:  We need to first evaluate the sub-condition (true || false) first

if ((true || false) && false) {

     /* True Block */

} else {

     /* False Block */

}

Step 2:  We need to evaluate the resulting expression now

if (true && false) {

     /* True Block */

} else {

     /* This will be false because the first conditional (true || false) is actually true, therefore your left with true && false, which is false. */

}

So here is how it should look (using only two checks):

if ((left(Call.CallingLineID,6) == "317948" || left(Call.CallingLineID,6) == "317944") && Global.user_MH_Nutrition_AftHrsFlag == "3") {

     /* True Block */

} else {

     /* This will be false just like you thought it should */

}

View solution in original post

(left(Call.CallingLineID,6)="317948"||left(Call.CallingLineID,6)="317944"||left(Call.CallingLineID,6)="317274"||left(Call.CallingLineID,6)="317278")&&Global.user_MH_Nutrition_AftHrsFlag="3"

david

View solution in original post

5 Replies 5

Anthony Holloway
Cisco Employee
Cisco Employee

You need to wrap your caller ID conditionals in parenthesis because || and && are short-circuit operators, or lazy evaluators.

Let's shorten it up to two caller ID checks:

if (left(Call.CallingLineID,6) == "317948" || left(Call.CallingLineID,6) == "317944" && Global.user_MH_Nutrition_AftHrsFlag == "3") {

     /* True Block */

} else {

     /* False Block */

}

If we let:

Call.CallingLineID == "317948XXXX"

Global.user_MH_Nutrition_AftHrsFlag == "0"

Then with a little substitution we have:

if (true || false && false) {

     /* This will be true because the first true halts evaluation of the expressions on the right hand side of the || operator */

} else {

     /* False Block */

}

Now if we include parenthesis, using the same substituted values we have:

Step 1:  We need to first evaluate the sub-condition (true || false) first

if ((true || false) && false) {

     /* True Block */

} else {

     /* False Block */

}

Step 2:  We need to evaluate the resulting expression now

if (true && false) {

     /* True Block */

} else {

     /* This will be false because the first conditional (true || false) is actually true, therefore your left with true && false, which is false. */

}

So here is how it should look (using only two checks):

if ((left(Call.CallingLineID,6) == "317948" || left(Call.CallingLineID,6) == "317944") && Global.user_MH_Nutrition_AftHrsFlag == "3") {

     /* True Block */

} else {

     /* This will be false just like you thought it should */

}

You da man!  Thanks!

Now I can delete the 3 extra nodes I was using as a work around.

Del

So...that worked?  Because I was totally guessing.

LOL Nice!

I just monitored the script and everything is flowing perfectly which means I dont have to get up at 10pm and 6:30am and move lines around in my ICM script.

I think I will celebrate my new knowledge by going to watch office space.

Thanks again Anthony!

Del

(left(Call.CallingLineID,6)="317948"||left(Call.CallingLineID,6)="317944"||left(Call.CallingLineID,6)="317274"||left(Call.CallingLineID,6)="317278")&&Global.user_MH_Nutrition_AftHrsFlag="3"

david

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: