Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- Acrobat SDK
- >
- the Custom Calculation Script

New Here
,

Dec 28, 2017

Copy link to clipboard

Copied

hi All,

I have no experience in creating calculation scripts in Adobe Acrobat, but now having made a transition to a paperless office, I need to create some new documents that have java calculation scripts within.

Initially the documents were in excel format and had Sum calculations at the bottom of each range.

i.e.

A1:A5 have single numbers from 1 thru 5

A6 was a sum of A1:A5 but with a twist!

The sum only rounded up if the sum was greater than .6 (point 6)

and rounded down if the sum was less than .6 (point 6)

My original excel calculation is shown below if it helps

=IFERROR(IF(MOD(AVERAGE(A1:A5),1)>0.5,ROUNDUP(AVERAGE(A1:A5),0),ROUNDDOWN(AVERAGE(A1:A5),0)),0)

I assume this will use the Adobe text box names a references to calculate a sum, rather than a cell reference, but I am a little lost.

Can anyone assist in creating a java calculation to achieve the same result?

Product is Adobe Acrobat Student Teacher Edition 2017, but this is only installed on a few systems, Adobe Reader DC is the main application form filling forms.

Thanks

Most Valuable Participant

Here, I've simplified it for you... If you want to edit the fields list it's just the first line of the code:

var fields = ["Text7", "Text8", "Text9", "Text10", "Text11"];

var total = 0;

var n = 0;

for (var i in fields) {

var f = this.getField(fields

);var v = Number(f.valueAsString);

if (v==0) continue;

total+=v;

n++;

}

if (n==0) event.value = "";

else {

var avg = total/n;

var mod = avg-Math.floor(avg);

if (mod>=0.6) event.value = Math.ceil(avg);

else event.value = Math.floor(avg);

}

TOPICS

Acrobat SDK and JavaScript,
Windows

Community Guidelines

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

New Here
,

Dec 28, 2017

Copy link to clipboard

Copied

hi All,

I have no experience in creating calculation scripts in Adobe Acrobat, but now having made a transition to a paperless office, I need to create some new documents that have java calculation scripts within.

Initially the documents were in excel format and had Sum calculations at the bottom of each range.

i.e.

A1:A5 have single numbers from 1 thru 5

A6 was a sum of A1:A5 but with a twist!

The sum only rounded up if the sum was greater than .6 (point 6)

and rounded down if the sum was less than .6 (point 6)

My original excel calculation is shown below if it helps

=IFERROR(IF(MOD(AVERAGE(A1:A5),1)>0.5,ROUNDUP(AVERAGE(A1:A5),0),ROUNDDOWN(AVERAGE(A1:A5),0)),0)

I assume this will use the Adobe text box names a references to calculate a sum, rather than a cell reference, but I am a little lost.

Can anyone assist in creating a java calculation to achieve the same result?

Product is Adobe Acrobat Student Teacher Edition 2017, but this is only installed on a few systems, Adobe Reader DC is the main application form filling forms.

Thanks

Most Valuable Participant

Here, I've simplified it for you... If you want to edit the fields list it's just the first line of the code:

var fields = ["Text7", "Text8", "Text9", "Text10", "Text11"];

var total = 0;

var n = 0;

for (var i in fields) {

var f = this.getField(fields

);var v = Number(f.valueAsString);

if (v==0) continue;

total+=v;

n++;

}

if (n==0) event.value = "";

else {

var avg = total/n;

var mod = avg-Math.floor(avg);

if (mod>=0.6) event.value = Math.ceil(avg);

else event.value = Math.floor(avg);

}

TOPICS

Acrobat SDK and JavaScript,
Windows

Community Guidelines

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

johnl62149758

Dec 28, 2017
0
/t5/acrobat-sdk/the-custom-calculation-script/td-p/9636370
8
Replies
8

Most Valuable Participant
,

Dec 28, 2017

Copy link to clipboard

Copied

Community Guidelines

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

Reply

Loading...

try67

Dec 28, 2017
0
/t5/acrobat-sdk/the-custom-calculation-script/m-p/9636371#M26334
New Here
,

Dec 28, 2017

Copy link to clipboard

Copied

Thanks for the reply,

Sorry for the typo. As you pointed out, this is an average calculation which I am trying to figure out.

I am so used to using sum/Average in calculations I messed up my explanation.

Thanks for the clarification

Community Guidelines

Reply

Loading...

johnl62149758

Dec 28, 2017
0
/t5/acrobat-sdk/the-custom-calculation-script/m-p/9636372#M26335
Most Valuable Participant
,

Dec 28, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

try67

Dec 28, 2017
0
/t5/acrobat-sdk/the-custom-calculation-script/m-p/9636373#M26336
New Here
,

Dec 28, 2017

Copy link to clipboard

Copied

Hi

For now, lets just call the text boxes "text1" thru "text5" then I can modify the names later to suit

Some other ranges and calculations on the form have only 4 text boxes to average, but I assume this would be fairly easy to modify once I have a good staring point.

All fields are blank until data is entered but all fields are mandatory. I guess the calculation script could include error code to manage any divide by zero error on opening the form or saving between data input points.

There are no zeros, 1 thru 5 are the values to input and must be entered in each text box by the data input user.

Hope this helps

Thanks

Community Guidelines

Reply

Loading...

johnl62149758

Dec 28, 2017
0
/t5/acrobat-sdk/the-custom-calculation-script/m-p/9636374#M26337
Most Valuable Participant
,

Dec 28, 2017

Copy link to clipboard

Copied

When the form is reset, though, the fields will become blank (unless you set a different default value), so you must take this scenario into consideration. I will have it ignore those empty values, for the moment.

You can use this code as your custom calculation script:

var total = 0;

var n = 0;

for (var i=1; i<=5; i++) {

var f = this.getField("text"+i);

var v = Number(f.valueAsString);

if (v==0) continue;

total+=v;

n++;

}

if (n==0) event.value = "";

else {

var avg = total/n;

var mod = avg-Math.floor(avg);

if (mod>=0.6) event.value = Math.ceil(avg);

else event.value = Math.floor(avg);

}

Community Guidelines

Reply

Loading...

try67

Dec 28, 2017
0
/t5/acrobat-sdk/the-custom-calculation-script/m-p/9636375#M26338
New Here
,

Dec 28, 2017

Copy link to clipboard

Copied

Hi ,

Appreciate your help here.

Although I said I may be able to modify based on text box names later, I look at the script and think not.

I bow to your knowledge and apologise for my flippant comment.

I now need a little more help to implement this.

The first range of text boxes are currently named Text7, Text8, Text9, Text10, Text11

With this added, I "may" be able to modify for further use, when I see where the reference is held within the script.

Thanks

Community Guidelines

Reply

Loading...

johnl62149758

Dec 28, 2017
0
/t5/acrobat-sdk/the-custom-calculation-script/m-p/9636376#M26339
Most Valuable Participant
,

Dec 28, 2017

Copy link to clipboard

Copied

Here, I've simplified it for you... If you want to edit the fields list it's just the first line of the code:

var fields = ["Text7", "Text8", "Text9", "Text10", "Text11"];

var total = 0;

var n = 0;

for (var i in fields) {

var f = this.getField(fields

);var v = Number(f.valueAsString);

if (v==0) continue;

total+=v;

n++;

}

if (n==0) event.value = "";

else {

var avg = total/n;

var mod = avg-Math.floor(avg);

if (mod>=0.6) event.value = Math.ceil(avg);

else event.value = Math.floor(avg);

}

Community Guidelines

Reply

Loading...

try67

Dec 28, 2017
1
/t5/acrobat-sdk/the-custom-calculation-script/m-p/9636377#M26340
johnl62149758
LATEST

New Here
,

Dec 28, 2017

Copy link to clipboard

Copied

Perfect, thank you so much

Community Guidelines

Reply

Loading...

johnl62149758

Dec 28, 2017
0
/t5/acrobat-sdk/the-custom-calculation-script/m-p/9636378#M26341
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.