Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Relative form element reference doesn't work on the server, for some cases.


Level 8

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: [2704] @@@: sfDetrimentalConditions is undefined at line: 14 of script:

1:  //dbg.logMsg("START form1.sfDetrimentalAddendum.#variables[0].opr");

2:  UTIL.init?UTIL.init():"";

3:  //JIRA: NE-3601 - The logic to control the Addendum Fragment

4:  //      This fragment has the necessary layout and logic to control hide/show

5:  //      and also control the default settings of the related conditions.

6:  //      When condition default value changes, the user should be able to

7:  //      override the set default value.


9:  //Get the parent container subform of this fragment.

10:  //This is needed since we don't know what will be the name of the fragment during runtime.

11:  //var frgSubformParent = sfDetrimentalConditions.parent.parent;


13:  //This is essentially same as "frgSubformParent" ... we will see how to simplify this

14:  var theFragmentParent = theFragmentParent || sfDetrimentalConditions.parent.parent;

15:  var theFragment = getFragment();


17:  //Constants

18:  var condition =

19:  {apparent: "apparent",

20:  notApparent: "not apparent",

2018-02-27 11:51:04,241 WARN  [com.adobe.document.XMLFormService] (RequestProcessor-3) ALC-XTG-032-108: [2704] Script failed (language is javascript; context is xfa[0].form[0].form1[0].subform[31].sfDetrimentalAddendum[0].sfDetrimentalConditions[0])

2018-02-27 11:51:04,241 WARN  [com.adobe.document.XMLFormService] (RequestProcessor-3) ALC-XTG-032-108: [2704] Script failed (language is javascript; context is xfa[0].form[0].form1[0].subform[31].sfDetrimentalAddendum[0].sfDetrimentalConditions[0])

script=//dbg.logMsg("START form1.sfDetrimentalAddendum.sfDetrimentalConditions::calculate");


2018-02-27 11:51:04,242 WARN  [com.adobe.document.XMLFormService] (RequestProcessor-3) ALC-XTG-032-275: [2704] 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;

var theFragment = getFragment();

function getFragment() {

var theNodes;

var result = null;

var errMsg;

//dbg.logMsg("DCA - getFragment - theFragmentParent = " + theFragmentParent);

if (theFragmentParent) {

result = theFragmentParent.resolveNode("$..sfHeader");

//dbg.logMsg("DCA - theFragmentParent name = " + theFragmentParent.name + " - result name = " + result.name);

result = result.parent;


if (!result) {

errMsg = "Unexpected error in getFragment() of 'frgDetrimentalAddendum': result parent is null or undefined.";


throw errMsg;




return result;


function setFragmentParent(prmSubform) {


//dbg.logMsg("prmSubform.somExpression = " + (prmSubform?prmSubform.somExpression:"*null*"));

theFragmentParent = prmSubform;


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.


0 Replies