I have a function that is creating a comma separated list of service providers. It's calling organization name and phone number, and I don't know where to place my sort code to alphabetize the list. I've tried many places and the below is the only one that seems to not break the drop down list I'm calling the function from, but it's also not sorting the list either.
Please help I've placed sort at the very bottom, but it's not sorting.
{!fn ServProvs()
{
local a = getrowcount("_ServiceProviders")
local temp = ""
local ret = ""
for i = 0, i < a, i = i + 1
do
temp = getrow("_ServiceProviders",i,"ListName","Phone1", "Specialty")
if ((temp[1] == "") AND (temp[2] == "")) then
continue
endif
if (ret "") then
ret = ret + ","
endif
if (temp[3] == "LMHA") then
cond
case ((temp[1] "") AND (temp[2] ""))
ret = ret + replacestr(temp[1], ",", ";") + " Phone: " + replacestr(temp[2], ",", ";")
case (temp[1] "")
ret = ret + replacestr(temp[1], ",", ";")
case (temp[2] "")
ret = ret + replacestr(temp[2], ",", ";")
else
//not sure how we got here
continue
endcond
endif
endfor
return ret
sort(ret, TRUE)
}}
Let me know if you have already tried this, but swap the positions of the last two lines of code. Once the return command is called anything following it does not get processed. So in the example you posted the sort command will never get processed.
Brad
sort() sorts an array. Instead of constantly adding to the string with retVal = retVal + whatever, you should declare retVal with local retVal = array() and then populate it with insert(retVal,1,whatever). Then at the end, do the sort, and return retVal. If you want you can return str(retVal) but returning the array should also work to populate a dropdown or listbox.
The 'whatever' that I have above should be a string of all of the fields you want in each row. So you can do the cond statment the same way, but store each provider in a different temp variable (called whatever here) and then insert that temp variable into the array, otherwise each little bit of data would be on a separate line. I hope that makes sense, let me know if you have any other questions.
thank you bhoover that helps me understand why it's not working. Yes, I already did try to place it above and it breaks my drop down by not allowing the drop down to drop after import.
gibsonmi, i think you understand this one. I'm trying to follow along but am not getting it. Is there any way you can help with what the code may look like?
Try this -
{!fn ServProvs() {
local temp
local rowString = ""
local ret = array()
for i = 0, i < getrowcount("_ServiceProviders"), i = i + 1 do
temp = getrow("_ServiceProviders",i,"ListName","Phone1", "Specialty")
if ((temp[1] <> "") or (temp[2] <> "")) then
if (temp[3] == "LMHA") then
cond
case ((temp[1] <> "") AND (temp[2] <> ""))
rowString = replacestr(temp[1], ",", ";") + " Phone: " + replacestr(temp[2], ",", ";")
case (temp[1] <> "")
rowString = replacestr(temp[1], ",", ";")
case (temp[2] <> "")
rowString = replacestr(temp[2], ",", ";")
endcond
insert(ret,1,rowString)
endif
endif
endfor
return sort(ret, TRUE)
}}
This works great. Thanks a ton!