I've spent the better part of an afternoon trying to puzzle this out. It's incredibly unimportant, but if it worked, my form would be SO much cleaner.
Basically, I have three tiers of dropdown menus, each one providing a more detailed list of the one before. All of these are pulling their lists from an .ini file, using a MEL expression. I want to use a function to determine which list to pull from the .ini.
Here's a basic drilldown of what I have:
TIER ONE - Housing: Permanent, Transitional, Other
TIER TWO (Permanent) - Independent, Supportive, Long Term, Family
TIER THREE (Family) - Parent, Spouse, Sibling, Friend
Right now, I have one dropdown in TIER ONE, two in TIER TWO, and almost twenty in TIER THREE.
I want to put a function into TIER TWO that would use if statements to determine which TIER THREE list to pull from. Here's what I've tried:
{
fn getHousType() {
if match(OBSNOW("DCHOUSING"), "Trans") > 0 then
getListFromTxt("[HOUS_TRANS]")
else
if match(OBSNOW("DCHOUSING"), "Perm") > 0 then
getListFromTXT("[HOUS_PERM]")
else
endif
endif
}
}
The getListFromTxt() function is an old custom function we use that basically uses the FILEOPEN, FILEREAD, and FILECLOSE functions to access data from an .ini file and use it to populate dropdowns. If I simply run the function by itself in the MEL field, I get the data I want.
I have tried DOCUMENT.HOUS_TYPE = getListFromTxt(etc), I have tried str(getListFromTxt(etc()), I have tried taking the raw data from the .ini list and putting into the function, but nothing works. I have even tried skipping the function call altogether, putting the if statement directly into the dropdown.
I simply think you cannot call a function inside a dynamic dropdown, but I thought I'd ask here, just in case. Again, it's really not important, but it's something MEL SHOULD be able to do, and if it CAN, I'd be saved from having thirty to forty individual dropdowns layered on top of each other within visibility regions.
I don't want to jump the gun here, but I think I got it...
Instead of using any additional functions, I ended up using the preexisting getListFromTXT() function, then having the if statements select the list INSIDE the parens.
{
getListFromTXT(
if (OBSNOW("DCHOUSING") == "Transitional") then
"[HOUSING_TRANS]"
else
"[HOUSING_OTHER]"
endif
)
}
That worked! Now hopefully I'll be able to chain these together...
You need to place a call to the function in the dynamic dropdown box, the definition goes in the white space to the right. so you could say
{getHousType(OBSNOW("DCHOUSING"))}
in the dynamic dropdown, and
{!fn getHousType(type){
if match(type,"Trans") > 0 then
getListFromTxt("[HOUS_TRANS]")
else
if match(type,"Perm") > 0 then
getListFromTXT("[HOUS_PERM]")
else ""
endif
endif
}}
in the white space. It is very important that any function definition used for a dynamic dropdown has the '!' in front of the fn, if not it will not be available when it is first used and you will get MEL errors.
As previously suggested, you could re-write the function to include arguments which would trigger the refresh of the lists instead of the adding the if then separately - cleaner and more controlled, especially with the periodic screen refresh issues the EMR suffers from.
{!
gHousingTypeList = getHousType(obsnow("DCHOUSING"))
}
{! gHousingTypeList // paste this variable in the dynamic list field of the dropdown}
{!fn getHousType(type)
{
local retStr = ""
cond
case match(type,"Trans") > 0 retStr = getListFromTxt("[HOUS_TRANS]")
case match(type,"Perm") > 0 retStr = getListFromTXT("[HOUS_PERM]")
else retStr = getListFromTXT("[HOUS_OTHER]")
endcond
return retStr
}
}
I am pretty sure I tried a variation of both of these answers, but since I hadn't made it work, obviously I was still missing something... This is a LOT cleaner, and I had no idea you could use "case" in MEL!
Thanks for the insight and the assistance on this one. Now when we update the lists, we only have to change it in the back end.