Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

EASY array question (I would think...)

Avatar

Level 1

I am trying to perform a simple calculation and put the results into each field of an array of numeric fields.  I am using Javascript in LifeCycle 8.

e.g. #1

var Total;

Total = 23;

nf[0].rawValue = Total;

nf[1].rawValue = Total + 1;

THIS DOESN'T WORK ????  I also tried the following

e.g.

var Total;

Total = 23;

nf.rawValue = Total;

nf.index = 1;

nf.rawValue = Total + 1;

This also doesn't work. please help me add values to specific items within the numeric field array, this is driving me nuts.....

1 Reply

Avatar

Level 1

One thing that should help is to turn on the debugger in adobe reader in the preview pane.  You can do this by right-clicking anywhere, click Page Display Properties, then click Javascript, and check off the console window.

From how you have things here you haven't defined nf as a variable.  The console should error back stating that nf is undefined.  If you create the array variable first it should work fine.  Should look something like this:

var number = [];

number[0] = 2;
number[1] = 3;

var total = number[0] + number[1];
equals.rawValue = total;

This works as array variables.  If you are trying to use field names, you need to change it slightly.  The correct formatting to specifiy and instance of a field would be:

fieldname[1].rawValue = whatever variable or value

The problem here is that this syntax in Livecycle for specifying the instance of that field conflicts with the syntax for javascripting, the '[]' makes livecycle think that you are dealing with an array.  So in order to get you need to use the structure:

xfa.resolveNode("fieldname[1]").rawValue

This then uses a function to resolves the node name and avoids trying to take the [] brackets literally.

Hope this helps, I had the same trouble.  Just gotta get used to the syntax.

Josh