Hello everyone,
I built a simple function to pull in all new orders and display the following,
cptcode + name + icdcode+ icd description.
If i put the following function in a test form, and use a button to add in a order, it will not display anything. However if I move to a different form or page, and back, it will display properly.
More problematically, if I move back to a different page or form, and back again, this information duplicates.
Anyone have any ideas why this happens?
{
fn fnOrderWithDx(){
local hold = getfield(Orders_new("delimited"),"|","")
local temp = ""
local temp2 = ""
local strfinal = ""
for i = 1, i <= size(hold), i = i + 1 do
temp = getfield(hold[i], "^", "")
temp2 = temp[3] + " - " + temp[1] + " " + temp[26] + " - " + temp[6] + hret
strfinal = strfinal + temp2
endfor
return strfinal
}
}
function call in data display is,
{fnOrderWithDx()}
Thanks for any suggestions
First problem is the function definition is not initialized before the data display tries to run it, change the definition to include a '!'
{!fn fnOrderWithDx(){
Second part, you never reset strfinal or declare it as a local variable, just changing
local final = ""
to
local strfinal = ""
should fix it
Silly mistake, I renamed it from strfinal to final when i uploaded it to chug, to make it slightly easier to read, and i forgot to rename it everywhere else.
Now initializing the function fixes the duplicates appearing everywhere. However I still need to switch to a different page or tab for the data display to actually populate. Is there any way to fix that?
Thanks for the help!
Making this change should fix that, adding the '!' to the function definition in the white space to the right
{!fn fnOrderWithDx(){
Timing in MEL is the bane of my existence! sorry, had to get that out of my system.
Usually, to avoid this scenario, I will declare a variable and call the function on that variable. like so:
{!orderStrVar = fnOrderWithDx()}
and then in my data display, I would call:
{orderStrVar}
This way, the MEL code knows that it has to compile the function and call it immediately, instead of waiting for the form to reload and call the function again properly.
That fixes the duplicate issue, however I still have to switch to a different form or page for the data display to populate
Interesting, how would that look like?
Whitespace:
{global orderStrVar} //declare
{!orderStrVar = fnOrderWithDx()} // assign
{
fn fnOrderWithDx(){...}
{orderStrVar} //function call in data display
Is that what it should look like?
Thats not working for me at the moment
{! fn fnOrderWithDx(){...} // declare function
{!global orderStrVar = fnOrderWithDx()} // assign and declare at the same time
{orderStrVar} //function call in data display
Don't forget the Exclamation point in both the function definition, and the variable declaration. this makes both sets of code run before the form loads completely. Let me know if it still gives you a fit, and I will do my best to put this into a test form and try it out. 🙂
Thank you,
Dan,
Edit For anyone experiencing this problem:
The following by user "jfitzmd" worked perfectly
{document.OrderWithDx=fnOrderWithDx(Orders_new("deliminted"))}
{fn fnOrderWithDx(){
local hold = getfield(Orders_new("delimited"),"|","")
local temp = ""
local temp2 = ""
local strfinal = ""
for i = 1, i <= size(hold), i = i + 1 do
temp = getfield(hold[i], "^", "")
temp2 = temp[3] + " - " + temp[1] + " " + temp[26] + " - " + temp[6] + hret
strfinal = strfinal + temp2
endfor
return strfinal}}
In data display:
document.OrderWithDx
You do have to put the document variable in your form, optionally under a visibility to hide it