Here's what I use in a dynamic single selection Listbox. I have one for Tests and another for Referrals. Enjoy!
(I started with someone else's function and changed it to meet my needs, so there may be some superfluous coding here. I was just happy it worked!)
/*
Creates list of Referrals and displays Details.
*/
{! fn ordList(strList)
{
local orderdate
local lCounter
local strOrdList
local lBuffer
local lBuffer2
local lBuffer3
local lBuffer4
local lBuffer5
local lBuffer6
local lBuffer7
local lBuffer8
local lBuffer9
local lBuffer10
local status = ""
local strFormattedList = ""
strOrdList = getfield(strList, "|", "")
for lCounter = 1, lCounter <= size(strOrdList), lCounter = lCounter + 1 do
strOrdList[lCounter] = getfield(strOrdList[lCounter], "^", "")
/* Only look at referrals entered in the past 180 days. */
orderdate = strOrdList[lCounter][4]
if (DURATIONDAYS(orderdate,str(._TODAYSDATE)) < 180) then
/* Need to remove commas */
lBuffer = strOrdList[lCounter][1]
lBuffer = ReplaceStr(lBuffer, ",", ";")
lBuffer2 = strOrdList[lCounter][8]
lBuffer2 = ReplaceStr(lBuffer2,",",";")
lBuffer3 = strOrdList[lCounter][6]
lBuffer3 = ReplaceStr(lBuffer3,",",";")
lBuffer4 = strOrdList[lCounter][21]
lBuffer4 = ReplaceStr(lBuffer4,",",";")
lBuffer5 = strOrdList[lCounter][19]
lBuffer5 = ReplaceStr(lBuffer5,",",";")
lBuffer6 = strOrdList[lCounter][18]
lBuffer6 = ReplaceStr(lBuffer6,",",";")
lBuffer7 = strOrdList[lCounter][4]
lBuffer7 = ReplaceStr(lBuffer7,",",";")
lBuffer8 = strOrdList[lCounter][5]
lBuffer8 = ReplaceStr(lBuffer8,",",";")
lBuffer9 = strOrdList[lCounter][20]
lBuffer9 = ReplaceStr(lBuffer9,",",";")
ordering_user = (find("_MasterOrders","USRID","OrderNum",strOrdList[lCounter][25]))
ordering_user_name = (find("_UserSearch","RealName","PVID",ordering_user))
lBuffer10 = ReplaceStr(ordering_user_name,",",";")
cond
case lBuffer9 == "U" status = "UNSIGNED (Referral has not yet been signed)"
case lBuffer9 == "H" status = "ADMIN HOLD (not yet scheduled)"
case lBuffer9 == "S" status = "IN PROCESS (scheduling currently in process)"
case lBuffer9 == "C" status = "COMPLETE (Referral has been scheduled)"
case lBuffer9 == "X" status = "CANCELED"
endcond
strFormattedList = strFormattedList + lBuffer + " [" + strOrdList[lCounter][3] + "] " + HRET + "Problem: " + numtoascii(9) + lBuffer3 + HRET + "Start Date: " + numtoascii(9) + lBuffer7 + numtoascii(9) + "End Date: " + lBuffer8 + HRET + "Status:" + numtoascii(9) + numtoascii(9) + status + HRET + "Entered by: " + numtoascii(9) + lBuffer10 + HRET + "Authorized by: " + numtoascii(9) + lBuffer4 + HRET + HRET + "Comments: " + HRET + lBuffer2 + HRET + HRET + "Administrative Comments: " + numtoascii(9) + lBuffer5 + HRET + HRET + "Authorization Number: " + lBuffer6 + ","
else ""
endif
endfor
if (lCounter > 1) then
strFormattedList = remove(strFormattedList, size(strFormattedList))
endif
return (strFormattedList)
}
}
/*
Creates list of Tests and displays Details.
*/
{! fn testList(strList)
{
local orderdate
local lCounter
local strOrdList
local lBuffer
local lBuffer2
local lBuffer3
local lBuffer4
local lBuffer5
local lBuffer6
local lBuffer7
local lBuffer8
local lBuffer9
local lBuffer10
local service_fax = ""
local status = ""
local strFormattedList = ""
strOrdList = getfield(strList, "|", "")
for lCounter = 1, lCounter <= size(strOrdList), lCounter = lCounter + 1 do
strOrdList[lCounter] = getfield(strOrdList[lCounter], "^", "")
/* Only look at TESTS that are not yet completed. */
if (strOrdList[lCounter][20] <> "C")then
/* Need to remove commas */
lBuffer = strOrdList[lCounter][1]
lBuffer = ReplaceStr(lBuffer, ",", ";")
lBuffer2 = strOrdList[lCounter][8]
lBuffer2 = ReplaceStr(lBuffer2,",",";")
lBuffer3 = strOrdList[lCounter][6]
lBuffer3 = ReplaceStr(lBuffer3,",",";")
lBuffer4 = strOrdList[lCounter][21]
lBuffer4 = ReplaceStr(lBuffer4,",",";")
lBuffer5 = strOrdList[lCounter][19]
lBuffer5 = ReplaceStr(lBuffer5,",",";")
lBuffer6 = strOrdList[lCounter][18]
lBuffer6 = ReplaceStr(lBuffer6,",",";")
lBuffer7 = strOrdList[lCounter][4]
lBuffer7 = ReplaceStr(lBuffer7,",",";")
lBuffer8 = strOrdList[lCounter][5]
lBuffer8 = ReplaceStr(lBuffer8,",",";")
lBuffer9 = strOrdList[lCounter][20]
lBuffer9 = ReplaceStr(lBuffer9,",",";")
ordering_user = (find("_MasterOrders","USRID","OrderNum",strOrdList[lCounter][25]))
ordering_user_name = (find("_UserSearch","RealName","PVID",ordering_user))
lBuffer10 = ReplaceStr(ordering_user_name,",",";")
service_fax = (find("_ServiceProviders","faxPhone","primPhone",strOrdList[lCounter][17]))
lBuffer11 = ReplaceStr(service_fax,",",";")
lBuffer12 = strOrdList[lCounter][13]
lBuffer12 = ReplaceStr(lBuffer12,",",";")
lBuffer13 = strOrdList[lCounter][17]
lBuffer13 = ReplaceStr(lBuffer13,",",";")
cond
case lBuffer9 == "U" status = "UNSIGNED"
case lBuffer9 == "H" status = "ADMIN HOLD"
case lBuffer9 == "S" status = "IN PROCESS"
case lBuffer9 == "C" status = "COMPLETE"
case lBuffer9 == "X" status = "CANCELED"
endcond
strFormattedList = strFormattedList + lBuffer + " [" + strOrdList[lCounter][3] + "] " + HRET + "Problem: " + numtoascii(9) + lBuffer3 + HRET + "Start Date: " + numtoascii(9) + lBuffer7 + numtoascii(9) + "End Date: " + lBuffer8 + HRET + "Status:" + numtoascii(9) + numtoascii(9) + status + HRET + "Entered by: " + numtoascii(9) + lBuffer10 + HRET + "Authorized by: " + numtoascii(9) + lBuffer4 + HRET + HRET + "Comments: " + HRET + lBuffer2 + HRET + HRET + "Service Provider:" + numtoascii(9) + lBuffer12 + HRET + numtoascii(9) + numtoascii(9) + lBuffer13 + " (phone)" + HRET + numtoascii(9) + numtoascii(9) + lBuffer11 + " (fax)" + ","
else ""
endif
endfor
if (lCounter > 1) then
strFormattedList = remove(strFormattedList, size(strFormattedList))
endif
return (strFormattedList)
}
}