Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Community Member

Proper format for If statement

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

Re: Proper format for If statement

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 */

}

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Re: Proper format for If statement

(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

5 REPLIES

Re: Proper format for If statement

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 */

}

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
Community Member

Re: Proper format for If statement

You da man!  Thanks!

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

Del

Re: Proper format for If statement

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

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
Community Member

Re: Proper format for If statement

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

Re: Proper format for If statement

(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

334
Views
0
Helpful
5
Replies
CreatePlease to create content