Copy link to clipboard
Copied
I've added a calculation script to 'CDOHrs' text field to add the total sum when CDO Banked is selected from the Absence drop down selection. However, I have another 'TotalHrs' text field which I would like to have all other hours calculated, except when CDO Banked is selected from the dropdown list. But, I also need the hours to calculate if no selection has been entered for Absence Type. I'm stuck on how to do that part. Any help would be greatly appreciated. I've attached a document as an example. I hope this makes sense. Thank you!!
Assuming the fields all follow the same name pattern you can use this code as the custom calculation script of the TotalHrs field, then:
var maxFields = 2; // adjust this value to 45 in the full version
var total = 0;
for (var i=1; i<=maxFields; i++) {
if (this.getField("AbsencePayTypeDesc"+i).valueAsString!="CDO Banked (worked on CDO)")
total+=Number(this.getField("RegHrs"+i).valueAsString);
}
event.value = total;
Copy link to clipboard
Copied
So basically you want Total Hrs to be RegHrs1 + RegHrs2, unless the "CDO Banked (worked on CDO)" option is selected in their corresponding Absence Type drop-downs?
Copy link to clipboard
Copied
Ya, I actually have up to RegHrs45 on my form, but basically that's what I need. It will help the user to have the total hours calculated for CDO Banked in a seperate field, and all other hours in the Total Hours text field.
Copy link to clipboard
Copied
Assuming the fields all follow the same name pattern you can use this code as the custom calculation script of the TotalHrs field, then:
var maxFields = 2; // adjust this value to 45 in the full version
var total = 0;
for (var i=1; i<=maxFields; i++) {
if (this.getField("AbsencePayTypeDesc"+i).valueAsString!="CDO Banked (worked on CDO)")
total+=Number(this.getField("RegHrs"+i).valueAsString);
}
event.value = total;
Copy link to clipboard
Copied
Fantastic! That works beautiful!! Thank you so much!!