Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Tools > Action Wizard JavaScript

New Here ,
Aug 17, 2018 Aug 17, 2018

I have a list of pdf documents, all of them have "ABC" field which is a sum of fields Field1 and Field2. I need to change the rule and add one more filed to the sum.

I use Tools>Action Wizard and JavaScript like this:

var f = this.getField("ABC");

f.setAction('Calculate',  "AFSimple_Calculate(\"SUM\", \"Field1, Field2, Field3\");" );

But after applying the action to the docs nothing was changed. What am I doing wrong?

Thanks!

TOPICS
Acrobat SDK and JavaScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 17, 2018 Aug 17, 2018

This code works as expected for me:

var f = this.getField("ABC");

f.setAction("Calculate", "AFSimple_Calculate(\"SUM\", new Array(\"Field1\", \"Field2\", \"Field3\"));");

Translate
LEGEND ,
Aug 17, 2018 Aug 17, 2018

Did you add a Save step?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2018 Aug 17, 2018

Sure, I did. For instance, this code works OK

var f = this.getField("GELEOtherClothing");

f.value = 100;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2018 Aug 17, 2018

It seems to apply the script, but it's not reflected in the calculate tab of the field properties dialog as you would expect. Is the calculation being performed correctly for you?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2018 Aug 17, 2018

The fields are blank, they are to be populated by users. I added some test values and the calculation performed correctly. But this is not what I need. I need to change the filed properties. Our designer made a mistake, he missed some fileds to be sum up. More that 50 copies of the document was created and all of them have the same issue of course. I would like to write a script to fix all the documents using Tools>Action Wizard instead of fixing each document manually. Is it possible?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2018 Aug 17, 2018

This code works as expected for me:

var f = this.getField("ABC");

f.setAction("Calculate", "AFSimple_Calculate(\"SUM\", new Array(\"Field1\", \"Field2\", \"Field3\"));");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2018 Aug 17, 2018
LATEST

Thanks! George_Johnson code works OK!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 17, 2018 Aug 17, 2018

In addition to adding a Save step, add this line to the end of your code:

this.calculateNow();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2018 Aug 17, 2018

Thanks for your answer, but with this.calculateNow(); the result is the same, nothing was changed in the docs.

May be I wasnt clear. I dont need the field to be re-calculated on doing JavaScript, I need to change field's property, the list of fields to be sum up. Am I on the right way?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 17, 2018 Aug 17, 2018

You do need to perform a re-calculation, because just setting a new action to the field's Calculation event does not actually trigger it.

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