Copy link to clipboard
Copied
Can you help me with the following? In my Adobe fillable form, I want the output to be rounded to the nearest quarter hour, so in this case, 9.75.
INPUT (UnitsRow1): Enter Units per Month: 1,200
OUTPUT (AvgRow1): Average Hours Per Day: 9.86
I also have the following Custom Format Script
if (event.target.value >= 10) {
event.target.textColor = ["RGB", 255/255, 0, 0];
}
else if (event.target.value <= 10) {
event.target.textColor = ["RGB", 0, 0, 0];
}
var x = Number(event.value);
if(event.value)
event.value = x.toFixed(2) ;
And a custom validation script:
event.target.textColor = (event.value > 10 || event.value < 10) ? color.black : color.red;
Copy link to clipboard
Copied
Instead of simplified field notation use custom calculation script:
var unitsPerMonth = Number(this.getField("UnitsRow1").value);
var hoursPerDay = (unitsPerMonth * 12) / 365 / 4;
hoursPerDay = Math.round(hoursPerDay * 4) / 4;
event.value = hoursPerDay;
There is no need to have both custom format and validation scripts for text color.
Copy link to clipboard
Copied
Thank you very much for your time and help; I appreciate it.
To round AvgRow1 (and AvgRow2 and AvgRow2) to the nearest quarter hour, I changed the simplified field notation to the custom calculation script you provided, which worked. However, several more calculated fields are on the form, and this negatively affects OutcomeRow1, OutcomeRow2, and OutcomeRow3. I tried changing the Text field properties for OutcomeRow1, 2, and 3 to var v1, var v2, and var v3, but it didn’t seem to fix the issue. What am I missing?
ABC Eligibility Calculation
UnitsRow1: Enter Units per Month: 1,200
AvgRow1: Average Hours Per Day: 9.86
Format. Custom Format Script:
if (event.target.value >= 10) {
event.target.textColor = ["RGB", 255/255, 0, 0];
}
else if (event.target.value <= 10) {
event.target.textColor = ["RGB", 0, 0, 0];
}
var x = Number(event.value);
if(event.value)
event.value = x.toFixed(2) ;
Validate. Hours not to exceed 10 per day. Run custom validation script:
event.target.textColor = (event.value > 10 || event.value < 10) ? color.black : color.red;
Calculate. Custom calculation script:
var unitsPerMonth = Number(this.getField("UnitsRow1").value);
var hoursPerDay = (unitsPerMonth * 12) / 365 / 4;
hoursPerDay = Math.round(hoursPerDay * 4) / 4;
event.value = hoursPerDay;
OutcomeRow1:
Calculate. Custom calculation script:
var v1 = Number(this.getField("AvgRow1").valueAsString);
event.value = (v1>=1) ? "Qualifies for ABC, provides one or more hours of service per day." : "Does NOT qualify for ABC, provides less than one hour of service per day.";
CDE Eligibility Calculation
UnitsRow2: Enter Units per Month: 1,000
AvgRow2: Average Hours Per Day: 8.25
Format. Custom Format Script:
if (event.target.value >= 10) {
event.target.textColor = ["RGB", 255/255, 0, 0];
}
else if (event.target.value <= 10) {
event.target.textColor = ["RGB", 0, 0, 0];
}
var x = Number(event.value);
if(event.value)
event.value = x.toFixed(2) ;
Validate. Hours not to exceed 10 per day. Run custom validation script:
event.target.textColor = (event.value > 10 || event.value < 10) ? color.black : color.red;
Calculate. Custom calculation script:
var unitsPerMonth = Number(this.getField("UnitsRow2").value);
var hoursPerDay = (unitsPerMonth * 12) / 365 / 4;
hoursPerDay = Math.round(hoursPerDay * 4) / 4;
event.value = hoursPerDay;
OutcomeRow2:
Calculate. Custom calculation script:
var v1 = Number(this.getField("AvgRow2").valueAsString);
event.value = (v1>=3) ? "Qualifies for CDE, provides three or more hours of service per day." : "Does NOT qualify for CDE, provides less than three hours of service per day.";
EFG Eligibility Calculation
UnitsRow3: Enter Units per Month: 1,000
AvgRow3: Average Hours Per Day: 8.25
Format. Custom Format Script:
if (event.target.value >= 10) {
event.target.textColor = ["RGB", 255/255, 0, 0];
}
else if (event.target.value <= 10) {
event.target.textColor = ["RGB", 0, 0, 0];
}
var x = Number(event.value);
if(event.value)
event.value = x.toFixed(2) ;
Validate. Hours not to exceed 10 per day. Run custom validation script:
event.target.textColor = (event.value > 10 || event.value < 10) ? color.black : color.red;
Calculate. Custom calculation script:
var unitsPerMonth = Number(this.getField("UnitsRow3").value);
var hoursPerDay = (unitsPerMonth * 12) / 365 / 4;
hoursPerDay = Math.round(hoursPerDay * 4) / 4;
event.value = hoursPerDay;
OutcomeRow3:
Calculate. Custom calculation script:
var v1 = Number(this.getField("AvgRow3").valueAsString);
event.value = (v1>=1) ? "Qualifies for EFG, provides one or more hours of care per day." : "Does NOT qualify for EFG, provides less than one hour of service per day.";
Copy link to clipboard
Copied
It didn't affect other fields, your field calculation order is not correct, select 'Prepare form' tool, then click on 'More' then select 'Set field calculation order', OutcomeRow fields should be under Avg fields:
Wrong: Correct:
Copy link to clipboard
Copied
Thank you so very much. :tulip::sun_with_face: