The numFields property returns the total number of fields in the document.
System.Int32 numFields();
Returns the current property value.
This property is Read-Only
Member of doc.
for (var i = 0; i < this.numFields; i++)
app.alert("Field[" + i + "]: " + this.getNthFieldName(i));