Expand my Community achievements bar.

JavaScript Execution

Avatar

Level 3

Hi,

I am working on a static xdp template and stuck at a point where JavaScript doesn't work anymore.

I am trying to show/hide subforms depending on the values of XML nodes in the XML file.

I have tried the following:

- Get the values of XML nodes form the XML file and store it in a variable.

For example:

var test = xfa.data.resolveNode("Document.Data.General_Information...").value;

if(test == "yes") {

     //show subform

} else {

     //hide subform

}

It looks simple but i have to get the values for 400 variables and if a node is missing from the XML file javascript breaks at that point and doesn't process or get the values for rest of the variables.

example:

var 1 = xfa.data.resolvnode.....

var 2 = xfa.data.resolvnode.....

var 3  = xfa.data.resolvnode.....

var 4 = xfa.data.resolvnode.....

if a node is missing in the XML file at var 2, javascript doesn't execute or get the values for var 3 and var 4.

How do I solve this problem? Any suggestions?

5 Replies

Avatar

Level 10

Hi,

The resolveNode method will return null if the element does not exist so try;

var test = xfa.data.resolveNode("Document.Data.General_Information...");

if(test !== null && test.value == "yes") {

     //show subform

} else {

     //hide subform

}

Regards

Bruce

Avatar

Level 3

Bruce,

Tried your suggestion but it didn't work. I might be doing something wrong. I have declared a group of variables that I am going to use i.e. 10 variables and once the script doesn't find the node in the XML code just breaks. It doesn't even try to get to the next line.

For example:

var test1 = xfa.data.resolveNode("Document.Data.General_Information...");

var test2 = xfa.data.resolveNode("Document.Data.General_Information...");

var test3 = xfa.data.resolveNode("Document.Data.General_Information...");

var test4 = xfa.data.resolveNode("Document.Data.General_Information...");

var test5 = xfa.data.resolveNode("Document.Data.General_Information...");

if a node doesn't exist for test4, code doesn't run for test5.. it just breaks.

Avatar

Level 10

Hi,

It wont be the resolveNode method itself causing the break just because the node isn't there.  Do you get any error messages poping up?  In Acrobat under Edit ... Preferences ... JavaScript you should have

  • "Enable JavaScript debugger ...",  checked
  • When exception is thrown set to break (or maybe trace)
  • Show console on errors and messages.

Failing all that you might need to post the complete code fragment or better still a sample of the form

Regards

Bruce

Avatar

Level 3

@BR001 - Thanks for your comment. Yes, i do get an error message in the Errors palette saying that form returned a null object but nothing on console. I do have javascript debugger enabled. one of my colleagues wrote javascript on each subform and he hid the subform first followed by if else statement. This seems to work for some reason.

for example:

this.sf.presence = "hidden";

var test = xfa.data.resolvenode(Document.FirstParagraph..);

if

{

     //something

}

else

{

    //something

}

He still gets error messages in the message palette but document works fine. Not sure If i wanna go with the same process.

Avatar

Level 10

How I understand you want to make this you will need to make a recursive method to get through all nodes in the xdp file...

Create a script object with a function that receives a subform as param1 and then for each nodes inside that subform call this method back until you find the objects you want to work with...