Skip to main content
Participant
November 16, 2020
Answered

Creating a Custom Calculation Script in Adobe Acrobat Pro DC

  • November 16, 2020
  • 2 replies
  • 1442 views

So.. I know nothing about JavaScript. Simply tooling around with PDF as a potential proposal tool.

 

I'm trying to apply operators (less than, greater than, equal to) to an existing output  "Propsal Score", that will create an output in a second box "Accountig Type". If my Value Sum from "Proposal Score" is between 0 an 50, how do I have the second text box populate:

  • "Cash Basis" if the Proposal Score is 0-10   
  • "Hybrid Basis" if the Proposal score is 11-30
  • "Accrual Basis" if the Proposal score is 31-50

Really appreciate any help!!!

This topic has been closed for replies.
Correct answer ls_rbls

Thank you! All acknowledged.

2 replies

Participant
November 17, 2020

Thank you, thank you. ls_rbls and try67.

 

I used your input, with subtle changes, and it worked!

 

var proScore  = this.getField("Proposal Score").valueAsString;

 

event.value ="";

 

if (proScore !=="") {

 

if (proScore >= 0 && proScore <= 10) { event.value = "Cash Basis"}

if (proScore >= 11 && proScore <= 30) { event.value = "Hybrid Basis"}

if (proScore >= 31 && proScore <= 50) { event.value = "Accrual Basis"}

 

}

 

ls_rbls
Community Expert
Community Expert
November 17, 2020

I think you can employ an IF condition in a custom calculation script like this:

 

var propType  = this.getField("Proposal Type").valueAsString;

event.value ="";

if (propType !=="") {

if (propType >= "0" && propType <= "10") { event.value = "Cash Basis"}
if (propType >= "11" && propType <= "30") { event.value = "Hybrid Basis"}
if (propType >= "31" && propType <= "50") { event.value = "Accrual Basis"}

} 

 

I am running this script as a custom calculation script in the "Accounting Type" text box

try67
Community Expert
Community Expert
November 17, 2020

When comparing numbers one must not place them in quotes, as that converts them to strings.

To see the difference run the following code in the JS Console:

 

console.println(100>30);
console.println("100">"30");

ls_rbls
Community Expert
ls_rblsCommunity ExpertCorrect answer
Community Expert
November 17, 2020

Thank you! All acknowledged.