These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Document Level Script

mjh
Registered: May 25 2007
Posts: 6
Answered

I usually write calculation scripts in text fields but would like to move forward into more document level function calling scripts. Just to begin, I thought I would write a document level script to read all the input variables and maybe place them into an array to be used by other funtions.

I tried:

function list()
{
this.calculate = false

var d = this.getField("d")
var e = this.getField("e")
var f = this.getField("f")
var g = this.getField("g")
var h = this.getField("h")

var list = newArray(d.value,e.value,f.value,g.value,h.value)

return list
}
(I have a calculate button to tell it when to turn calculate to true).
But I have not successfully gained access to my variables in other functions or at the field level.

Is this the right approach or do I just have an error?

Any input will be helpful and is appreciated.

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Not only do you need to set the "calculate" property to true, but you need to force a field value change to trigger the calculate acion.

So your button might have a mouse up action of:

console.show(); console.clear();
var MyArray = list(); // get return from function
console.println(MyArray) // print MyArray
console.println(MyArray.length); // number of elements
for(i = 0; i < MyArray.length; i++) // list elements
console.println(i + ": " + MyArray[i]);
console.println(MyArray.join('/')); // print element with a '/' between elements


I would use the following document level script:

// start of document level script
// turn off the auto calculation for this document upon opening
this.calculate = false;

function list() {
var alist = new Array(); // array for field values
var sField
// loop through the fields
for (var i = 0; i < this.numFields; i++) {
sField = this.getNthFieldName(i); // get field name
// skip button fields
if(this.getField(sField).type != 'button')
alist[alist.length] = this.getField(sField).value; // use adjusted length for alist
} // end loop through field names

return alist; // return array of values
}
// end of document level script

George Kaiser

mjh
Registered: May 25 2007
Posts: 6
Thanks so much for your time.

mjh