I have about 20 fields, named A through T.
I want field T to calculate the average of fields A through S, and ignore any fields that are blank. I would use the built in average calculator, but the blank fields give it problems. Does anyone know a script for this?
What are your field names?
In general, you'd loop through the fields and get their values using the valueAsString property, so you can distinguish between a blank value and a value of zero. Convert the string value to a number and keep a running sum and count of non-blank fields. You can then calculate the average given the sum and number of non-blank fields.
You can search the forums for 'average' and you should find a working script.
Although you might want to have functions for count, sum and average that build upon one another. You could count the number of fields with a non-blank value, and then if the count is not zero, sum the fields and then compute the average. You would then have the functions available for other forms.
Thanks, I found one.