If Statement Issue


#1

Hi there, new here.

Having an issue running an if statement. I want to run the proceeding commands if a value in the csv I’m calling is equal to “Lunch”, “Coffee/Snacks” or “Dinner”. I think there’s something wrong with my logic.

Command: if
Target: ${Expense Type} = “Lunch” || “Coffee/Snacks” || “Dinner” || “Breakfast”
Value:

Thanks in advance!


#2

I should mention that I’m able to open the CSV and use the Expense Type variable with other commands, so thats not an issue.


#3

Hi,

did you use “endIf” command? I had an issue when i used “if” comand with “|”, If i’m not wrong i figured it out but i don’t have access right now to this test case. Maybe try to use single “|” not double, also you may try to use double “=” and try to use just one of those word to compare to Expense variable at the time to check if “if” command work properlly when it’s much simpler.


#4

In addition to using the endIf statement and ==, you will also need to enclose the variable in quotations marks
"${ExpenseType}" and make sure the other values are enclosed in plain quotation marks i.e. "Dinner", not “Dinner”
Also, each part of the if statement needs to return a valid boolean value (true/false).

Try this:

store | Dinner | ExpenseType |
if | "${ExpenseType}" == "Lunch" || "${ExpenseType}" == "Coffee/Snacks" || "${ExpenseType}" == "Dinner" || "${ExpenseType}" == "Breakfast" | |
echo | Found ${ExpenseType} | |
endIf | | |

Also note I haven’t used a space in the variable name. Most programming languages do not allow spaces in variable names.