I came across very strange case where the relative form/field reference doesn't work on the server side. In such cases, I see error on the server log like the following log related to subform "sfDetrimentalConditions":
2018-02-27 11:51:02,904 INFO [com.adobe.document.XMLFormService] (RequestProcessor-3) ALC-XTG-000-000:  @@@: sfDetrimentalConditions is undefined at line: 14 of script:
2018-02-27 11:51:04,242 WARN [com.adobe.document.XMLFormService] (RequestProcessor-3) ALC-XTG-032-275:  Error: hideShow is not a function
The form tree looks like the following:
As you can see, there is extensive use for fragments. I noticed this kind of error will happen only on the server, and in some cases, not always. However, if the referenced functions or variables are under the root form, then there is no problem. The problem is so apparent if the script is under a subform such as in script object "DCATools" above.
I was able to solve the problem by resolving a fully qualified reference to the form elements or functions. This is becoming so annoying and very challenging especially after I realized that the variables defined in script objects are having global reference.
I am using the following code snippet to resolve a fully qualified reference to the subform when it is a fragment. Since we don't know the fragment name until runtime, so we have to use something like the following:
var theFragmentParent = theFragmentParent || xfa.resolveNode("form1..sfDetrimentalConditions").parent.parent;
So, the parent form (of the fragment) will set a reference to itself in the child subform (fragment) using function "setFragmentParent()". There are two global variables in this case:
- theFragmentParent (the parent of the fragment")
- theFragment (the fragment itself)
I noticed that the above approach will solve the problem to a good extent, but too much complicated coding. Another issue is that since I have many fragments, then the variable "theFragment" is completely messed up since it will have global scope on the server. I am not sure how to overcome this problem. This means I have to give unique name for the variables "theFragmentParent" and "theFragment" in each fragment, but if the same fragment is used two or more times in the same form, then there is a trouble here.
Why the scope of local script variables have global scope if the form is running on the server?
Please someone take a look at this problem and suggest to me what I can do to find a clean and decent solution.