Expand my Community achievements bar.

check field in loop doesn't work

Avatar

Level 2

Hi,

I am trying to check if my field value is in a table which is used to provide the elements of a drop down list. As the user you can also enter something free in that field I have to check it against the table.

I tried to manage that with the following script but it is not working. There mus be something wrong in my script.

var loNodes = xfa.record.Y_ITAB_COUNTRY_EU.nodes;

var loNodesRow;

var lLength = loNodes.length;

for (i=0; i<lLength; i++)

{

if ( this.rawValue == xfa.resolve.Node("xfa.record.Y_ITAB_COUNTRY_EU[" + i + "].DATA.LAND1").rawValue ) {

}

else {

alert("country not in table");

Y_TAB_COUNTRY_EU is the table which is used for the drop down list.

here is the xml strucutre of the table.

- <Y_ITAB_COUNTRY_EU>
- <DATA xfa:dataNode="dataGroup">
<EKORG>AT01</EKORG>
<LAND1>DE</LAND1>
<EU>X</EU>
</DATA>
- <DATA xfa:dataNode="dataGroup">
<EKORG>AT01</EKORG>
<LAND1 />
<EU>X</EU>
</DATA>
</Y_ITAB_COUNTRY_EU>
- <Y_ITAB_COUNTRY_NONEU>
- <DATA xfa:dataNode="dataGroup">
<EKORG />
<LAND1 />
<EU />
</DATA>
</Y_ITAB_COUNTRY_NONEU>

I would appreciate if you could let me know what I am doing wrong in the script.

Thank you.

Martin

7 Replies

Avatar

Level 10

Hi Martin,

Not sure if this will help...

You haven't declared i as a variable in the for statement:

for (var i=0; i<lLength; i++)

When previewing the form use the Javascript Console (Control+J in Acrobat or Preview mode). When you interact with the form any errors should show up in the console.

Niall

Avatar

Level 2

Hi Niall,

thanks for that hint. It still doesn't work. There still must be something else which is no right.

Martin

Avatar

Level 10

Bit by bit...

The if statement includes a resolveNode, but you have an extra full stop between resolve and node.

Try

xfa.resolveNode(...

The Javascript console should really show up an error. If you look at/post the error it should give a good direction at what is going wrong.

Niall

Avatar

Level 2

Hi,

now that I removed the full stop between resolve and node the comparison is working. But I discovered another problem now.

I build in a message box to see the values in the table (so that I can better correct errors). In the message box for my values in the table it says that the value in the table is: undefined

so even if I have the value "DE" in the filed HERKL and also in the table I have "DE" is says country not in table. because it says

value for HERKL: "DE" and value in the table "undefined"

here is my modifyed script:

var loNodes = xfa.record.Y_ITAB_COUNTRY_EU.nodes;
//var loNodesRow;
var lLength = loNodes.length;
var text1;
var text2;
for (var i=1; i<=lLength; i++)
{
text1 = this.rawValue;
xfa.host.messageBox("current country: " + text1);
text2 = xfa.resolveNode("xfa.record.Y_ITAB_COUNTRY_EU.DATA[" + i + "].LAND1").rawValue;
xfa.host.messageBox("country in table: " + text2);
if ( this.rawValue == xfa.resolveNode("xfa.record.Y_ITAB_COUNTRY_EU.DATA[" + i + "].LAND1").rawValue ) {
//xfa.host.messageBox("country in table");
}
else {
xfa.host.messageBox("country not in table");
}
}

So I am not sure if undefined means in that context. Could it be because I have a blant value in my table. Current values in my tabel are "DE" and space.

Could it be it says "undefined" because the typ of LAND1 of table Y_ITAB_COUNTRY_EU is LAND1 ?

Martin

Avatar

Level 10

Hi Martin,

You are now starting the for loop from var i=1, however the first node will be 0 and this first node includes DE. I think you should start the loop from var i=0.

Can you share the form?

Niall

Avatar

Former Community Member

Also if you are interogating the data dom you want to use the value property not the rawValue. rawValue is used when you want to get the value of a

field on the form. value is used when you want the value of a node in XML.

paul

Avatar

Level 2

Thanks Niall, thanks Paul.

I managed to solve my problem.

I changed var i = 1, back to var i = 0 and also I bound my table to a field (table) on my form. Then .rawValue was working.

Martin