cancel
Showing results for 
Search instead for 
Did you mean: 

cannot read data via javascript / data node is empty

0 Kudos

Hi,

i try to create a print form with Adobe Forms. The job is nearly done, but now i have to do following:

Depending on some data (which is not bound via data binding) i'd like to do some formatting (background color, font ...).

For this purpose i have inserted a javascript to the initialize-event:

this.rawValue = xfa.resolveNode("xfa.datasets.data.MY_FIELD").value;

But i get no data. The MY_FIELD node is not found.

After trying resolveNode with various paths, i tried

this.rawValue = xfa.resolveNode("xfa.datasets.data").saveXML();

Result:

<?xml version="1.0" encoding="UTF-8"?>

<xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup" />

The data node is empty. But why???

Data binding works. The data is passed to the form completely. I just cannot read it via script.

I don't want to use data binding with invisible fields and then read the field values, because i need this also in a table. Using invisible fields in table is not a good idea, because you cannot make table cells invisible without getting "holes" in your table

Any help appreciated!

Peter Herweg

Accepted Solutions (1)

Accepted Solutions (1)

NoJo
Active Participant
0 Kudos

Hi,

solution in Javascript

if you want to access the value of a field you can use two (perhps more?) ways.

Via the DATA node --> var myVar = xfa.resolveNode("xfa.record.MY_FIELD").rawValue or .value, depends on your type

Via the hierarchy node -->

var myVar = xfa.resolveNode("data.Page1.subform1.MY_FIELD").rawValue

But you can try this: if your cursor is positioned in the script editor for example after "var myVar = " hold the control (="Strg"?) button on your panel an go with the cursor to the relevant field --> a "V" will appear --> now do a left mouse click and the correct SOM expression will be copied to your script. You will just have to add "rawValue" or "Value"

for tables it's a little bit different...

tell me if it worked, please

br

norbert

Answers (1)

Answers (1)

Hi,

i found the solution by myself.

This is my script placed into the initialize-event of a table-row.


function pad(t, count) {
	var s = new String(t);
	while ( s.length <  count) {
	  s = '0' + s ;
	}
	
	return s;
}

for(var z=1;z<=31;++z) {
	var sDay = pad(z,2);

	var s    = "$record.TABLEDATA.DATA[" + this.index + "].DAYS.VALUE" + sDay;
	var oDay = this.resolveNode(s);

	if (oDay.HOLIDAY.value == "X"
	|| oDay.WEEKDAY_S.value == "SA"
	|| oDay.WEEKDAY_S.value == "SO") {
		this.resolveNode("SHORTSVALUE" + sDay).fillColor = "255,100,100";
	}
}

The problem was the SOM expression which is passed to resolveNode. I have a book which tells me to begin the SOM expression with xfa.datasets.data in order to access the data nodes. Obviously this is wrong You have to start with $record.

Kind regards,

Peter Herweg

Edited by: Peter Herweg on May 8, 2009 3:20 PM

Edited by: Peter Herweg on May 8, 2009 3:21 PM

Edited by: Peter Herweg on May 8, 2009 3:22 PM