Expand my Community achievements bar.

SOLVED

Node Existence?

Avatar

Former Community Member

I am trying to figure out if there is an easier way than my method for testing for the existence of an XML node using XDP JavaScript?

The problem of course is that if I look at the value of a node that doesn't exist, it throws an error and the entire calculate script bombs.  To date, I have been doing this using try/catch.  For example, I have a table in which I want to set the value of a cell based upon information in my XML

using the calculate event ...


var i = this.parent.index;     // get the row number so I can index into the XML

var document = xfa.datasets.data.resolveNode("Document["+i+"]");     // get the ith <Document/> element

var result;

var owner;


try

{

     owner = document.Owner.value;

     result = value;

}

catch(e)

{

     result = "N/A";

}


this.rawValue = result;

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If it was possible to bind your fields to the xml then you wouldn't have this problem.

But I assume it's not that simple so I would test the result of resolveNode for null

That is;

var i = this.parent.index;     // get the row number so I can index into the XML
var document = xfa.datasets.data.resolveNode("Document["+i+"]");     // get the ith <Document/> element
var result;
if (document !== null)
{
     result = document.Owner.value;
}
else
{
     result = "N/A";
}
this.rawValue = result;

Bruce

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

If it was possible to bind your fields to the xml then you wouldn't have this problem.

But I assume it's not that simple so I would test the result of resolveNode for null

That is;

var i = this.parent.index;     // get the row number so I can index into the XML
var document = xfa.datasets.data.resolveNode("Document["+i+"]");     // get the ith <Document/> element
var result;
if (document !== null)
{
     result = document.Owner.value;
}
else
{
     result = "N/A";
}
this.rawValue = result;

Bruce

Avatar

Former Community Member

Yeah, that make sense.  I will give it a try.