Apply calculation to multiple forms with incrementing loop

Nov 20, 2017

Copy link to clipboard

Copied

Hello,

What on earth am I missing here?

I don't think foo and baa and being outputted correctly with the appropriate backslashes (escaping?).

when executed I need the calculate command to be applied as:

"Calculate","AFSimple_Calculate(\"PRD\", new Array (\"hx\", \"rx\"))");

above the represents the incrementing number that starts at 1, it is stored in the variable [inc], seen below.

var targetArray = new Array("t1","t2","t3","t4","t5","t6","t7","t8");

for (i = 0; i < targetArray.length; i++){

var targetFields = this.getField(targetArray);

inc = i + 1;

var foo = "\"\h" + inc + "\"";

var baa = "\"\r" + inc + "\"";

targetFields.setAction("Calculate","AFSimple_Calculate(\"PRD\", new Array (foo, baa))");

};

Is it because foo and baa are not being pointed to their values from the 10th line?

Thanks Everyone!

M

Check the JS Console after changing the value of any field in the file.

You will probably see an error message that says something like "foo is undefined".

That is because these variables don't exist in the calculation script.

Change the last line in your code to:

targetFields.setAction("Calculate","AFSimple_Calculate(\"PRD\", new Array (\""+foo+"\", \""+baa+"\"))");

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

104

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Apply calculation to multiple forms with incrementing loop

Nov 20, 2017

Copy link to clipboard

Copied

Hello,

What on earth am I missing here?

I don't think foo and baa and being outputted correctly with the appropriate backslashes (escaping?).

when executed I need the calculate command to be applied as:

"Calculate","AFSimple_Calculate(\"PRD\", new Array (\"hx\", \"rx\"))");

above the represents the incrementing number that starts at 1, it is stored in the variable [inc], seen below.

var targetArray = new Array("t1","t2","t3","t4","t5","t6","t7","t8");

for (i = 0; i < targetArray.length; i++){

var targetFields = this.getField(targetArray);

inc = i + 1;

var foo = "\"\h" + inc + "\"";

var baa = "\"\r" + inc + "\"";

targetFields.setAction("Calculate","AFSimple_Calculate(\"PRD\", new Array (foo, baa))");

};

Is it because foo and baa are not being pointed to their values from the 10th line?

Thanks Everyone!

M

Check the JS Console after changing the value of any field in the file.

You will probably see an error message that says something like "foo is undefined".

That is because these variables don't exist in the calculation script.

Change the last line in your code to:

targetFields.setAction("Calculate","AFSimple_Calculate(\"PRD\", new Array (\""+foo+"\", \""+baa+"\"))");

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

105

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 20, 2017 0
Nov 21, 2017

Copy link to clipboard

Copied

Check the JS Console after changing the value of any field in the file.

You will probably see an error message that says something like "foo is undefined".

That is because these variables don't exist in the calculation script.

Change the last line in your code to:

targetFields.setAction("Calculate","AFSimple_Calculate(\"PRD\", new Array (\""+foo+"\", \""+baa+"\"))");

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2017 1
_mar LATEST
Nov 21, 2017

Copy link to clipboard

Copied

The colouration in syntax should've showed me that, right over my head. Thanks for your help try67, led me to the answer.

With that line changed the code still didn't function as intended, for anyone interested in achieving similar results here's code of the final custom action I created, thanks to try67.

var targetArray = new Array("t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8");

for (i = 0; i < targetArray.length; i++) {

  var targetFields = this.getField(targetArray);

  inc = i + 1;

  var foo = "h" + inc;

  var baa = "r" + inc;

  app.alert(foo);

  targetFields.setAction("Calculate", "AFSimple_Calculate(\"PRD\", new Array (\""+foo+"\", \""+baa+"\"))");

};

M

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2017 0