I have a form I just created that shows a sorted list of problems in a listbox. I have two different ways I want to allow the users to sort the list. I have a radio button with two sort options tied to a document variable called SORT_BY and clicking on either option fills in the problem listbox. The functionality of the sort works properly.
The listbox MEL code looks like this:
{ProblemList(DOCUMENT.SORT_BY)}
When the form loads, neither radio button is selected which makes for an empty listbox. (the ProblemList function doesn't run)
I would like to have one of radio buttons selected when the form loads so that the lisbox is always populated. I am able to select the radio button on the form load using this code:
If (DOCUMENT.SORT_BY == "") then
DOCUMENT.SORT_BY = "Alphabetical"
endif
When I use this code, loading the form selects the correct radio button, but it does not trigger the listbox to fill in the data. The only way I have been able to have it fill in the listbox is if I am the one to actually click the radio button.
Is there any way to accomplish this?
Placing a "!" infront of your code will force the line to be executed every time the form is loaded.
{
!If (DOCUMENT.SORT_BY == "") then
DOCUMENT.SORT_BY = "Alphabetical"
endif
}
Start with this and see if it resolves your issue.
-James
That was already in the code of both the if statement and the function.
In what order do the code segments appear? Keep in mind that when writing code in the right window (the MEL window), the code is loaded in the EMR in reverse order (bottom to top). If your statement is below the function, it might be triggering a MEL error that is preventing the proper execution of the button population on load. You can verify this in a MEL trace.
If the statement is above the function, a MEL trace might reveal a different error that is preventing the 'stack' from completing execution on load. Suffice to say, your code should work otherwise.
As a last ditch 'fix', you could code a hidden data display set to run process with the if-then statement in it. Place it somewhere at the top of the first page/tab. This would force the code to run once more when the form is initially drawn on screen. Keep in mind that this would be a bypass of the issue causing the failure, which really should be identified and remedied.
It must have been an order of functions issue. I tend to put all of my functions in a single {! } so it loaded my main function and ran it but the function that my main function used was beneath it in the same brackets. I moved it out to my library (I was always planning on having it there anyway, it just didn't want to keep restarting EMR) and restarted EMR and now it works.
The order went something like this:
{!
If (DOCUMENT.SORT_BY == "") then
DOCUMENT.SORT_BY = "Alphabetical"
endif
}
{!
fn ProblemList(){
...code...
local variable = secondfunction()
}
fn secondfunction(){
...code...
}
}
After reading the mel trace file I realized it was erroring out on the secondfunction() definition not being executable. I moved the "secondfunction()" to my library and all is well. Thank you.