Copy link to clipboard
Copied
I'm using the following custom calculation script in a text field named 'TotalOTHrs' and it works great. However, I also need to calculate the hours from another 35 dropdowns name 'MBHrs1' to 'MBHrs35. I'm strugging with how to input that and I could sure use some much appreciated help. Thanks.
var maxFields = 35; //
var total = 0;
for (var i=1; i<=maxFields; i++) {
if (this.getField("OTPayType"+i).valueAsString!="CDO Banked")
total+=Number(this.getField("OTHrs"+i).valueAsString);
}
event.value = total;
Copy link to clipboard
Copied
So if value from dropdown is not "CDO Banked" you want to calculate both "OTHrs" and "MBHrs"?
I ask because in your two posts you used different condition in first you use != "CDO Banked" and in second == "CDO Banked", so which one is it?
If OTHrs and MBHrs are in the same row for each dropdown, you can just sum them, like this:
total+=Number(this.getField("OTHrs"+i).valueAsString)+Number(this.getField("MBHrs"+i).valueAsString);
Copy link to clipboard
Copied
Hi there
Hope you are doing well and thanks for reaching out.
The workflow you are trying to achieve is might be possible using JavaScript. For more information, please check the help pages listed below:
https://acrobatusers.com/tutorials/javascript_console/
https://helpx.adobe.com/acrobat/using/applying-actions-scripts-pdfs.html
Hope it will help
Regards
Amal
Copy link to clipboard
Copied
I definitely need help with the script above so the total hours can calculate from both OTHrs and MBHrs into the text field 'TotalOTHrs', except when the user selects 'CDO Banked' from the OT PayType dropdown. Please help.
Note: I also have another text field named 'CDOBankedHrs' with the following custom calculation script, which is good.
var total = 0; for (var i=1; i<=35; i++) { if (this.getField("OTPayType"+i).valueAsString=="CDO Banked") total+=Number(this.getField("OTHrs"+i).valueAsString); } event.value = total;
Copy link to clipboard
Copied
So if value from dropdown is not "CDO Banked" you want to calculate both "OTHrs" and "MBHrs"?
I ask because in your two posts you used different condition in first you use != "CDO Banked" and in second == "CDO Banked", so which one is it?
If OTHrs and MBHrs are in the same row for each dropdown, you can just sum them, like this:
total+=Number(this.getField("OTHrs"+i).valueAsString)+Number(this.getField("MBHrs"+i).valueAsString);
Copy link to clipboard
Copied
Yes! That's exactly what I need! It works great now. Thank you Nesa!! You're the best 🙂
Copy link to clipboard
Copied
Nesa, I forgot something. I don't want the hours to calculate from OTHrs and MBHrs if 'Shift Premium 50%' is selected from the OTPayType dropdown, as well as 'CDO Banked' which is there now. How do I add that?
//Construction Total OTHrs
var maxFields = 35; //
var total = 0;
for (var i=1; i<=maxFields; i++) {
if (this.getField("OTPayType"+i).valueAsString!="CDO Banked")
total+=Number(this.getField("OTHrs"+i).valueAsString)+Number(this.getField("MBHrs"+i).valueAsString);
}
event.value = total;
Copy link to clipboard
Copied
Hi Nesa, I got it to work!
Copy link to clipboard
Copied
Glad you make it work, but your conditions may be a bit confusing, you can do it like this:
var total = 0;
for (var i=1; i<=35; i++) {
var drop = this.getField("OTPayType"+i).valueAsString;
var ot = Number(this.getField("OTHrs"+i).valueAsString);
var mb = Number(this.getField("MBHrs"+i).valueAsString);
if (drop != "CDO Banked" && drop != "Shift Premium 50%")
total += ot+mb;}
event.value = total;
Copy link to clipboard
Copied
Awesome!! Thanks Nesa!!
Copy link to clipboard
Copied
Hi there
We are glad to hear that.
Marking a reply or response “Correct” will help future users with the same issue quickly identify the correct answer.
~Amal