Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

Node Existence?

Avatar

Level 4

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

0 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