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

Custom Calculation Script Help - If/Then Statements

New Here ,
May 15, 2025 May 15, 2025

I am currently trying to modify our mileage sheet to do calculations automatically. Originally we were using simplified field notation of: (Miles1*0.67)+(Hours1*1.5)+(Misc1) to calculate the subtotal of each line.

 

Recently there has been a change though, 

The Hourly rate needs to be $17.00

The milage rates are .70 if they travel less than 99 miles and .44 if they travel 100 miles or more.

 

I've attached a screenshot naming each of the fields

 

magical_Lullaby4400_0-1747310972706.png

 

TOPICS
Modern Acrobat , PDF , PDF forms
88
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 ,
May 15, 2025 May 15, 2025
LATEST

You can try this as custom calculation script:

var miles = Number(this.getField("Miles1").valueAsString);
var hours = Number(this.getField("Hours1").valueAsString);
var misc = Number(this.getField("Misc1").valueAsString);

var mileRate = (miles > 0 && miles < 100) ? 0.70 : (miles >= 100 ? 0.44 : 0);

event.value = (miles * mileRate) + (hours * 17) + misc;

If those are all calculations you are using for subtotal, you may consider using a loop to calculate all rows with one script and grand total instead of using a script in each row.

EDIT:

Script for loop, use it in "GRAND TOTAL" field as custom calculation script:

var grandTotal = 0;

for(var i=1; i<=10; i++) {
 var miles = +this.getField("Miles"+i).valueAsString;
 var hours = +this.getField("Hours"+i).valueAsString;
 var misc = +this.getField("Misc"+i).valueAsString;
 var sub = this.getField("Subtotal"+i);

 var mileRate = (miles > 0 && miles < 100) ? 0.70 : (miles >= 100 ? 0.44 : 0);
 var total = (miles * mileRate) + (hours * 17) + misc;
  sub.value = total;
  grandTotal += total;}


event.value = grandTotal;
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