I know this question may sound trivial, but I am finding that the form I am currently looking at is not always regarded as the 'current' form when using an ADD_FORM_COMP button.
Consider this situation.....
I have forms A,B,C,D,E in an encounter type. On any given office visit, the user may enter clinical data in all 5 forms or he/she may skip one or more forms because it is not relevant to today's visit. Say the user enters data into form A, and on form A the user clicks a button to jump to form D. On form D, I have an ADD form component button set to add AFTER_CURRENT. When the user clicks the ADD form component button, the added form is inserted after form A so that the new list looks like: A,added_form,B,C,D,E. I wanted the list to be A,B,C,D,added_form,E.
However, if I close the form view at any time and select form D from the form list on the left, adding the form component works as desired : A,B,C,D,added_form,E
What are the criteria for how the ADD_FORM_COMP() function determines the 'current' form?
I was thinking of using getfield() and get_form_list() to generate an array of form names, looping through the array, and determining the index of the form I'm looking at. Then I can use the ordinal number version of ADD_FORM_COMP() to select where to add the form I need to add. This just seems like way to much work for something so simple, but I think I can do it.
I used:
{
fn get_form_num(form_name)
{
local form_list = ""
local form_array = ""
local i = ""
local j = ""
form_list = get_form_list()
form_array = getfield(form_list,"|","")
for i=1, i<size(form_array), i=i+1
do
form_array[i] = getfield(form_array[i],"^","")
endfor
for i=1, i<size(form_array), i=i+1
do
if(form_array[i][2]==form_name)then
BREAK
endif
endfor
return str(i)
}
}
to get the position of the form I'm currently looking at....
Then, I used ADD_FORM_COMP() and, instead of "AFTER_CURRENT", I used i+1 as the ordinal number to insert. This works how I want it to, but still seems like an unnecessary amount of work to me.
the forms list doesn't always get updated appropriately when adding forms. I've told GE about it many times.
jrea said:
I used:
{
fn get_form_num(form_name)
{
local form_list = ""
local form_array = ""
local i = ""
local j = ""
form_list = get_form_list()
form_array = getfield(form_list,"|","")
for i=1, i<size(form_array), i=i+1
do
form_array[i] = getfield(form_array[i],"^","")
endfor
for i=1, i<size(form_array), i=i+1
do
if(form_array[i][2]==form_name)then
BREAK
endif
endfor
return str(i)
}
}
to get the position of the form I'm currently looking at....
Then, I used ADD_FORM_COMP() and, instead of "AFTER_CURRENT", I used i+1 as the ordinal number to insert. This works how I want it to, but still seems like an unnecessary amount of work to me.
Thanks for sharing the code you wrote up for it. I'm having the same problem, and I was going to build exactly what you did. It would be nice if the AFTER_CURRENT worked as it is intended, though.
Thanks again!
No problem. I realized later that for FOR loops, i needed to use i<=size() instead of i<size(). MEL doesn't treat the first element of an array as the 0th element.
Like:
for i=1, i<=size(form_array), i=i+1
Instead of:
for i=1, i<size(form_array), i=i+1
Either way, it works pretty well. It just may not find your form if it's the very last one in the list if you use
for i=1, i<size(form_array), i=i+1