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

SOLVED

Conditional Data Binding

Centrex80
Level 2
Level 2

I would like to bind data to a table only on the condition that one of the child tags has a certain value.

For example, let's say my XML file had the following structure:

<tag>

     <condition>1</condition>

     ....

</tag>

I want to bind only if the condition tag has a value of '1'. Does anyone have an idea how this can be done?

Thanks

1 Accepted Solution
dcidev
Correct answer by
Level 8
Level 8

You need to use SOM predicates in your Data Binding expression. For example the binding expression for your entire table with the common parent of <Table> let's say, you could put:

$.Table.[tag.condition.value=='1']

Remember the '.' (period) after Table since that what tells the XFA parser to expect a boolean to determine whether to bind or not.

If you require more detail, please provide more xml and your form names/hierarchies.

Kyle

View solution in original post

4 Replies
dcidev
Correct answer by
Level 8
Level 8

You need to use SOM predicates in your Data Binding expression. For example the binding expression for your entire table with the common parent of <Table> let's say, you could put:

$.Table.[tag.condition.value=='1']

Remember the '.' (period) after Table since that what tells the XFA parser to expect a boolean to determine whether to bind or not.

If you require more detail, please provide more xml and your form names/hierarchies.

Kyle

View solution in original post

Centrex80
Level 2
Level 2

Thanks that resolves my question, but I also want to know how I would be able to use SOM predicates in javascipt code

I tried:

xfa.resolveNode("xfa.datasets.data.tag.[condition.value=='1'].TestValue").value

For an XML structured in this manner, except with multiple tags with different condition values:

<tag>

     <condition>1</condition>

     <TestValue>0</TestValue>

     ....

</tag>

....

dcidev
Level 8
Level 8

This will return all the tag nodes whose condition element equals 1:

xfa.resolveNodes('$record.tag.[condition=="1"]')

You can also use:

XMLData.applyXPath(xfa.data, "RootNode.tag[condition='1']")

if you're more familiar with xPath expressions. It's also faster (when you get up to around 10,000 entries).

Kyle