0

There's a tutorial on saptechnical that contains this piece of code. I can't find any info in the docs about code like this, and the code suggestion doesn't work.

I come from a Java background, so things like this scare me.

This apparently gets the value of all the PRICE fields on the current page and sums them up.

var fields = xfa.layout.pageContent(xfa.layout.page(this)-1, "field", 0);
var total = 0;
for (var i = 0; i <= fields.length-1; i++) {
    if (fields.item(i).name == "PRICE") {
        total = total + fields.item(i).rawValue;
    }
}
this.rawValue = total;

So how to find info about the complete API? (because for instance I don't know how to do this except with this "magic" piece of code.)

Is there more documentation than this? http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf

And why doesn't the code suggestion thingy work? (Oh, i'm also not that much of a Javascript dev).

dimo414
  • 47,227
  • 18
  • 148
  • 244
vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
  • 2
    "Any sufficiently advanced technology is indistinguishable from magic" - Arthur C. Clarke – Philipp Mar 28 '13 at 15:06
  • 2
    possible duplicate of [List attributes of an XFA Object using Javascript in a PDF](http://stackoverflow.com/questions/480167/list-attributes-of-an-xfa-object-using-javascript-in-a-pdf) – yms Mar 28 '13 at 19:45
  • 1
    You can download a version of [the Acrobat SDK from here](http://www.adobe.com/devnet/acrobat/sdk/eula.html), which includes the appropriate version of the **JavaScript™ for Acrobat® API Reference** (which by the way doesn't hold the required info, click through to the link in @yms comment for that). – Mathijs Flietstra Sep 17 '13 at 17:56

1 Answers1

0

This code doesn't really look magic to me.

var fields = xfa.layout.pageContent(xfa.layout.page(this)-1, "field", 0);

This gets an array with all fields from the page layout.

for (var i=0; i <= fields.length-1; i++) {

This is a for-loop over the indices of all fields.

if (fields.item(i).name == "PRICE") {
    total = total + fields.item(i).rawValue;
}

When the name of the field is "PRICE", add its value to the total.

 this.rawValue = total;

Set the value of this field to the calculated total

Philipp
  • 67,764
  • 9
  • 118
  • 153
  • 1
    I think what the requester was looking for is some reference documentation that explains what each of the objects referenced in this code mean and what other operations they support, so that he can adapt it to solve other problems. The PDF he linked to describes some interfaces but it's not clear how the objects shown in this code relate to those interfaces. – Martin Atkins Mar 28 '13 at 15:43
  • Indeed, that is my issue. In the docs, the 'xfa' object has no 'layout' property. and no 'layout' object exists that has a 'page' or 'pageContent" method - so i don't know how to use those or any other "hidden" objects and properties. – vlad-ardelean Mar 29 '13 at 08:52