fieldValues() method not necessarily returns values in the same order as fieldNames(). Replace values[i] with this.field(field)