refactor new_record js code