Need help with customized calculation script in Acrobat Pro

New Here ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

I've got a calculation worksheet going and have added the basic calculations to it but there is one field that requires something more complex - not even sure if it can be done but I thought I'd throw it out there. Here's a run down of the calculation that includes my field names:

fill_5 = the greater of fill_82 and fill_83 only when fill_81 is greater than $5000, otherwise, fill_5 = fill_82

If that's not possible, another route that would serve the same purpose for me would be:

fill_83 = fill_81 x 0.06 only when fill_81 is greater than $5000, otherwise, fill_83 = 0

*note the "0.06" is a field name

Can anyone help me out on figuring out if either of these is possible and how to script it out? 

TOPICS
How to , JavaScript , PDF forms

Views

83

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , May 06, 2022 May 06, 2022

Sure, it's possible. You can use this code as the field's custom calculation script:

 

if (Number(this.getField("fill_81").valueAsString)>5000)
	event.value = Math.max(Number(this.getField("fill_82").valueAsString), Number(this.getField("fill_83").valueAsString));
else event.value = this.getField("fill_82").valueAsString;

Likes

Translate

Translate
Adobe Community Professional ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

Sure, it's possible. You can use this code as the field's custom calculation script:

 

if (Number(this.getField("fill_81").valueAsString)>5000)
	event.value = Math.max(Number(this.getField("fill_82").valueAsString), Number(this.getField("fill_83").valueAsString));
else event.value = this.getField("fill_82").valueAsString;

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
community guidelines
New Here ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

LATEST

Woo! Thanks so much that works great!! 

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
community guidelines
Adobe Community Professional ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

You'll find this article helpful:

https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines