I am struggling with this one and other functions. Basically, when I add an If statement and the Return is blank I get <Bad Index. What is wrong with this?? If I remove "if IOrderArray[ICounter][2]=="S" then " and the else "" endif that goes with it, it works fine and returns all orders, or blank if there are none, but adding that exclusions causes errors if the return is blank.
{fn fnMedHTMLOrders2(strList)
{
local ICounter
local IOrderArray
local IStart
local IBuffer
local IFormattedList = ""
/* Create Array of orders */
IOrderArray = getfield(strList,"|","")
/* Loop through all problems in Array */
for ICounter = 1, ICounter <= size(IOrderArray), ICounter = ICounter + 1 do
/* Create Array for each order */
IOrderArray[ICounter] = getfield(IOrderArray[ICounter],"^","")
if IOrderArray[ICounter][2]=="S" then
IFormattedList = IFormattedList + IOrderArray[ICounter][1] + if IOrderArray[ICounter][10]"" then " (units " + IOrderArray[ICounter][10] + ")" else "" endif + " " + IOrderArray[ICounter][4] + HRET
else ""
endif
endfor
/* Remove trailing comma */
if (ICounter > 1) then
IFormattedList = remove(IFormattedList, size(IFormattedList))
endif
return (IFormattedList)
}}{fnMedHTMLOrders2(ORDERS_ALL("delimited"))}
Hello,
From first glance, it looks like you're missing a "<>" in the statement after IOrderArray[ICounter][10]. Try this:
if IOrderArray[ICounter][2]=="S" then
IFormattedList = IFormattedList + IOrderArray[ICounter][1] + if IOrderArray[ICounter][10]<>"" then " (units " + IOrderArray[ICounter][10] + ")" else "" endif + " " + IOrderArray[ICounter][4] + HRET
else ""
endif
Hope this helps!
SL
Here is the original function, I copied it and cut out some info because I'm getting the same <Bad Index result no matter how simple I write it. I must have lost that in the copy/paste.
{fn fnMedHTMLOrders(strList)
{
local ICounter
local IOrderArray
local IStart
local IBuffer
local IFormattedList = ""
local arrAUAMeds = array("CPT-J0270","CPT-J9031","CPT-J0585","CPT-J9155","CPT-J1040","CPT-J3490.21","CPT-J1580","CPT-J9225","CPT-J0897","CPT-J9357","CPT-J3301","CPT-J2001","CPT-J9217","CPT-S0020","CPT-J0275","CPT-J0696","CPT-J1720","CPT-S0189","CPT-J1071.1","CPT-J1071.2","CPT-J9357","CPT-J3490.4","CPT-J0775","CPT-J9202")
local IMedCounter
/* Create Array of orders */
IOrderArray = getfield(strList,"|","")
/* Loop through all problems in Array */
for ICounter = 1, ICounter <= size(IOrderArray), ICounter = ICounter + 1 do
/* Create Array for each order */
IOrderArray[ICounter] = getfield(IOrderArray[ICounter],"^","")
for IMedCounter = 1, IMedCounter <=size(arrAUAMeds), IMedCounter = IMedCounter + 1 do
if IOrderArray[ICounter][2]=="S" and (IOrderArray[ICounter][3]==arrAUAMeds[IMedCounter]) then
IFormattedList = IFormattedList + IOrderArray[ICounter][1] + if IOrderArray[ICounter][11]"" then " (units " + IOrderArray[ICounter][11] + ")" else "" endif + " " + IOrderArray[ICounter][4] + HRET + " Comments: " + IOrderArray[ICounter][8] + HRET + HRET
else ""
endif
endfor
endfor
/* Remove trailing comma */
if (ICounter > 1) then
IFormattedList = remove(IFormattedList, size(IFormattedList))
endif
return (IFormattedList)
}}{fnMedHTMLOrders(ORDERS_ALL("delimited"))}