Skip to main content
Known Participant
January 14, 2016
Question

what is wrong with my calculate script?

  • January 14, 2016
  • 2 replies
  • 845 views

I have a form within a document and can't figure out what is wrong.

The debugger error:

TypeError: getField(...) is null

10:Field:Calculate

TypeError: getField(...) is null

37:AcroForm:G.44:Calculate

TypeError: getField(...) is null

The (calculate) code in column 10 is:

(function () {

   // Get the field values, as numbers

   var A0 = +getField("A.0").value;

   var B0 = +getField("B.0").value;

   var C0 = +getField("C.0").value;

   var D0 = +getField("D.0").value;

   var E0 = +getField("E.0").value;

   var F0 = +getField("F.0").value;

   var G0 = +getField("G.0").value;

   var H0 = +getField("H.0").value;

   // Set this field’s value to the sum

   event.value = A0 + B0 + C0 + D0 + E0 + F0 + G0 + H0 ;

})()

There are 10 columns that add horizontally. (Column 9 is actually empty and not used, if that makes a difference)

And 44 rows that add vertically.

The error message multiples as I progress in the form/matrix, but regularly references the same "10" and "37", but the "G.44" is sometimes "M.44".

I keep staring and can't find the error.

This topic has been closed for replies.

2 replies

Inspiring
January 14, 2016

There is a way to trap the field name of the problem field or fields by writing a function that takes as input the field name and returns the field object or a null object and if the field name supplied does not match with a field object it alerts the user to the error.

function GetField(cName) {

var oField = this. getField(cName);

if(oField == null) {

app.alert("Error accessing field named " + cName, 1, 0);

}

return oField;

} // end GetField function;

(function () {

// Get the field values, as numbers

   var oA0 = GetField("A.0");

   var oB0 = GetField("B.0");

   var oC0 = GetField("C.0");

   var oD0 = GetField("D.0");

   var oE0 = GetField("E.0");

   var oF0 = GetField("F.0");

   var oG0 = GetField("G.0");

   var oH0 = etField("H.0");

g

   // Set this field’s value to the sum

   event.value = +oA0.value + =oB0.value + oC0.value + +oD0.value + oE0.value + +oF0.value + +oG0.value + oH0.value ;

})()

I try to stay away from self defining functions until the form has been debugged since this type of function sometimes hides the full error message.

Also I probably would have written a defined function to sum a the values of an array of field names so I could reuse the function to sum any given series of field names.

sue_kAuthor
Known Participant
January 18, 2016

Thank you for your time on this!

So appreciate you all in the forums!

try67
Community Expert
Community Expert
January 14, 2016

That error message means you're trying to access a field name which doesn't

exist.

sue_kAuthor
Known Participant
January 18, 2016

Thanks!

Finally found the two errors!