08-03-2010 11:57 AM - edited 03-14-2019 06:12 AM
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.
Solved! Go to Solution.
08-03-2010 01:55 PM
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 */
}
08-03-2010 08:37 PM
(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
08-03-2010 01:55 PM
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 */
}
08-03-2010 02:32 PM
You da man! Thanks!
Now I can delete the 3 extra nodes I was using as a work around.
Del
08-03-2010 03:48 PM
So...that worked? Because I was totally guessing.
08-03-2010 05:35 PM
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
08-03-2010 08:37 PM
(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
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: