Hello,
I just started with CPS, and created my first VFE form. It's a simple date picker with a dynamic list. I build the list using a custom function that pulls just the medication name from the MED_LAST function:
fn getMeds() {
local ret = ""
local meds = getfield(MEDS_AFTER("delimited"), "|", "")
for i = 1, i < size(meds), i = i + 1 do
local txt = meds[i]
local f = getfield(txt, "^", "")
ret = ret + f[1] + ","
endfor
return ret
}
Behind the list component on the form, I have "Dynamic Choice List" checked, and my MEL expression is this:
!getMeds()
When I go to add this form to a chart note, the very first time I add it, the list is blank. If I remove this form and re-add it, the list shows up. It doesn't matter how I add the form the first time, the list is ALWAYS blank. But if I remove and re-add, it works fine.
Is there some magic I need to do to have this work on the first try?
The '!' needs to go in front of the function definition, like
!fn getMesds()....
That will load the function before it is called and should populate the first time. You can remove the '!' from the MEL expression, you do not need it there.
That did it! Thanks. I learned!
Life is complicated. Some complex functions expected to be executed at load are not completed.
Set a document variable as the last line of your function: document.form_loaded="yes". Hide the variable on your form either in a visibility segment set to false, or just gray out the field with no label and a transparent background. That enables you to monitor execution of the function. As an example, the function to be executed is InitializationFunction. In the translation tab of the document variable form_loaded, execute the following: { if document.form_loaded<>"yes" then InitializationFunction() "" else "" endif}}
As written, you will have an extra row as you are always adding a ",". I prefer ret=ret+(if ret<>"",",","")+f[1]
Good Luck. Welcome to VFE. Contact me directly if you wish to discuss.