I'd like to use an IF / THEN function in VFE to push a separate observation term for each choice within a document variable list box. I've tried many variations of the funcation below but it's not working. Not sure what I'm doing wrong. I've tried combining them with OR, or by listing all the endif's at the end. Still not working.
What is the correct syntax to make it do this?
{IF ((DOCUMENT.FOLLOW_UP_PL)== "Diet Counseling") then (OBSNOW("DIET COUNSEL","yes"))
else ""
endif}
{IF ((DOCUMENT.FOLLOW_UP_PL)== "Diet Plan") then (OBSNOW("DIET PLAN","yes"))
else ""
endif}
{IF ((DOCUMENT.FOLLOW_UP_PL)== "Nutritional Goals") then (OBSNOW("NUTRITNL GL", "yes"))
else ""
endif}
{IF ((DOCUMENT.FOLLOW_UP_PL)== "Nutrition Guide") then (OBSNOW("NUTRITN GUID","yes"))
else ""
endif}
{IF ((DOCUMENT.FOLLOW_UP_PL)== "Balanced Calories Deficit Diet") then (OBSNOW("BCDD","yes"))
else ""
endif}
{IF ((DOCUMENT.FOLLOW_UP_PL)== "Diet Compliant") then (OBSNOW("DIETCMPLIANT","yes"))
else ""
endif}
{IF ((DOCUMENT.FOLLOW_UP_PL)== "Nutritional Intevention") then (OBSNOW("NUTRITIONIVN","yes"))
else ""
endif}
try:
cond
case DOCUMENT.FOLLOW_UP_PL == "Diet Counseling"
OBSNOW("DIET COUNSEL", "yes")
case DOCUMENT.FOLLOW_UP_PL == "Diet Plan"
OBSNOW("DIET PLAN", "yes")
case DOCUMENT.FOLLOW_UP_PL == "Nutritional Goals"
OBSNOW("NUTRITNL GL", "yes")
case DOCUMENT.FOLLOW_UP_PL == "Nutrition Guide"
OBSNOW("NUTRITN GUID", "yes")
case DOCUMENT.FOLLOW_UP_PL == "Balanced Calories Deficit Diet"
OBSNOW("BCDD","yes")
case DOCUMENT.FOLLOW_UP_PL == "Diet Compliant"
OBSNOW("DIETCMPLIANT", "yes")
case DOCUMENT.FOLLOW_UP_PL == "Nutritional Intevention"
OBSNOW("NUTRITIONIVN", "yes")
endcond
A listbox is only "equal" to a single response if it is the only response selected. You'll have to use "match" regardless of whether or not you use a cond/case or if/then. If more than one item is checked, the listbox is no longer "equal" to your single selection and thus "false". To be "true" it must only "contain" the result, so use match.
For example
{IF match(DOCUMENT.FOLLOW_UP_PL, "Diet Counseling") >0 then OBSNOW("DIET COUNSEL","yes")
else ""
endif}
The match worked perfectly. And the "equal" logic makes perfect sense. Appreciate your feedback and help with this.
Test your code for clearing the obs - test carefully to see what happens when you de-select the particular item from the list box to be sure your obs clears, or include the null assignment in your "else" statement, thus:
{IF match(DOCUMENT.FOLLOW_UP_PL, "Diet Counseling") >0 then OBSNOW("DIET COUNSEL","yes")
else obsnow("diet counsel","")
endif}
Sorry...didn't see you were using a listbox. The COND/Case won't work then...only recognizes the first case hit...won't continue checking the rest...have to use separate IF/THEN statements.