Two things stand out:
1) Declare the variables 'i' and 'z' as local.
i.e.
local i
local z
Remember: ALWAYS account for and make local your function variables, otherwise they will creep into the global space and produce unexpected results.
2) I think another problem may be that the quotes are not ascii(34) characters. MEL is very sensitive to the curly single and double quotes. It looks like they are curly here, but that could just be the way they were typed in. Be certain they are the straight single and double quote characters. I used your outline, fixed the quotes, and it worked fine.
"" (good) vs. ”” (evil)
Bonus: On occasion, MEL does not properly assign values when being initialized as local. To avoid this, always declare local on one line and assign on a separate line.
i.e.
local m4SummDashArry = ""
m4SummDashArry = getfield(MEDS_AFTER("delimited"),"|","")
This works:
{!fn fnPrettyMeds()
{
local tmpStr = ""
local tmpStr2 = ""
local strBuf = ""
local strTemp = ""
local i
local z
strTemp = getfield(MEDS_AFTER("delimited"),"|","")
for i = 1, i <= size(strTemp), i = i + 1 do
strTemp[i] = getfield(strTemp[i],"^","")
tmpStr = tmpStr + (if tmpStr == "" then "" else "|" endif) + strTemp[i][1] + " ("+ strTemp[i][2] + ") " + tolower(strTemp[i][7])
endfor
strBuf = getfield(tmpStr,"|","")
strBuf = sort(strBuf,TRUE)
for z = 1, z <= size(strBuf), z = z + 1 do
tmpStr2 = tmpStr2 + if strBuf[z] == "" then "" else str(z) + ") " + strBuf[z] + HRET endif
endfor
return tmpStr2
}
}
Edit - forgot to address the main issue:
Lastly, the thing you are looking for:
The failure of the function when re-entering the udpate indicates that the function is no longer in memory , so you need a command to ensure it is added each time the update is opened. In other words, when an update is re-opened, the text component must be reloaded as well. The best method to do this is to use the library functionality in VFE (VFE auto-inserts the MEL needed for you).
Note: Use of the userlib.txt file places the function in the global memory space. I advise against the use of the userlib for occasionally used functions. Remember - the content of the user lib remains in memory, even after the udpate is put on hold (unlike a text component - aka function library). This means you have an increased risk of variable collision/hijacking and even crossing data between charts. Additionally, the more you put into the userlib, the more 'weight' the EMR must carry around doing what it does - this can become problematic if the load gets too large (think in terms of watcher/execution cost ratios on the CPU). One should only use the userlib.txt file if they are sure they can identify and mitigate the risks involved.
Hope this helps!
Posted : August 3, 2017 5:06 pm