Copy link to clipboard
Copied
I have a column labeled "Number of Round Trips" for a monthly mileage report. Each field is labeled Trips1 through Trips31. I need to be able to calculate the number of days the vehicle is used. It would be an easy calculation if there were 30 - round trips and only one - 1/2 trip. How would one configure the JavaScript so that each 1/2 trip calculates as 1 day? For example, how can I calculate 27- round trips and 4 - 1/2 trips to be 31 days and not 29 days?
There are different ways you can do that. Can I assume that there is a maximum of one round trip per day?
If so, you could use the following script as your calculation script in your "totals" field:
var cnt = 0;
for (var i=0; i<=31; i++) {
var f = this.getField("Trips" + i);
if (f != null) {
if (Number(f.value) > 0)
cnt++;
}
}
event.value = cnt;
This will count anything that is larger than 0 as a day the vehicle was used.
Copy link to clipboard
Copied
There are different ways you can do that. Can I assume that there is a maximum of one round trip per day?
If so, you could use the following script as your calculation script in your "totals" field:
var cnt = 0;
for (var i=0; i<=31; i++) {
var f = this.getField("Trips" + i);
if (f != null) {
if (Number(f.value) > 0)
cnt++;
}
}
event.value = cnt;
This will count anything that is larger than 0 as a day the vehicle was used.
Copy link to clipboard
Copied
Thank you so very much for taking the time to help me!
It works perfectly☺
Michelle Sylvestre, (Personal/Business information removed. Email signatures and personal information )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now