Hello All,
I have a form with a column of document variables. I would like to dynamically access them based on passing a parameter. In my example each of the variables I am trying to access is named document.reason1, document.reason2, etc. The LineNum parameter indicates which line the document variable is on. So rather than doing this:
COND
CASE LineNum == 1
//A function here using document.reason1
CASE LineNum == 2
//A function here using document.reason2
//Then repeat many times.
ENDCOND
I thought I could do something like the following. I used the userok to test to see if I received the value in the document variable:
fn fnRmMed(LineNum)
{
userok("Reason is: " + eval("DOCUMENT.REASON"+LineNum))
}
Unfortunately I got a NULL value back. If you look at the MEL trace when you run the function it looks like it is trying to pull the value. I'm just not sure why it doesn't see it.
MelTrace] execute> "DOCUMENT.REASON" + 1
MelTrace] results> "DOCUMENT.REASON1"
MelTrace] execute> call EVAL("DOCUMENT.REASON1")
MelTrace] >>
MelTrace] Fire trigger: DOCUMENT.REASON1
MelTrace] execute>> Document.REASON1
MelTrace] results>> NULL
MelTrace] execute>> end
MelTrace] results>> NULL
MelTrace] execute>> Done with trigger
MelTrace]
MelTrace] results> ""
MelTrace] execute> "Reason is: " + ""
MelTrace] results> "Reason is: "
MelTrace] execute> call USEROK("Reason is: ")
MelTrace] results> FALSE
MelTrace] results> return FALSE
MelTrace] results>return FALSE
MelTrace] execute>end
MelTrace] results>FALSE
Any suggestions are greatly appreciated.
Thanks!
Brad
You will need to set your DOCUMENT Variables to global (a check box that says "Make available to other forms") if you want to use the function above. It should work as you are thinking, but unless you make the document variable available to other forms, the system changes the name of the variable to something like DOCUMENT.REASON1ABK34S21CF2. This is how you can have the same name in different forms, and the system doesn't get confused.
Be aware that you should make your global document variables VERY unique, so that you don't end up shooting yourself in the foot if you do the same thing in another form, and end up using the same name again. try something like DOCUMENT.FORMNAME_CLINICNAME_REASON1.
Let me know if you have any questions about this. 🙂
Thank you,
Daniel