Parameters
NameTypeDescription
recordsys.data.Record

This is the record that is being moved. You will usually update the rank field in this record using the methods in the wrapper methods

Keep in mind that you need to save the record after you update the rank field, otherwise rank won’t be updated and record won’t be moved.

recordBeforesys.data.RecordThis is the record that is before the position we want to move the record. It could be null if we are moving the record to the first position so there is no record before.
recordAftersys.data.RecordThis is the record that is after the position we want to move the record. It could be null if we are moving the record to the last position so there is no record after.
Samples
 
//rank records in a way that urgent ones are always at the top
var fieldName = 'rank';
var moved = false;
if (!recordBefore && recordAfter) { // the record is moved to the top
	if (!recordAfter.field('urgent').val() || record.field('urgent').val()) {
  	record.field(fieldName).rankBefore(recordAfter.field(fieldName));
  	moved = true;
	}
} else if (recordBefore && !recordAfter) { // the record is moved to the bottom
	if (recordBefore.field('urgent').val() || !record.field('urgent').val()) {
	  record.field(fieldName).rankAfter(recordBefore.field(fieldName));
	  moved = true;
	}
} else if (recordBefore && recordAfter) { // the record is placed between two other records
	if ((!recordAfter.field('urgent').val() || record.field('urgent').val()) &&
	    (recordBefore.field('urgent').val() || !record.field('urgent').val())) {
	  record.field(fieldName).rankBetween(recordBefore.field(fieldName), recordAfter.field(fieldName));
	  moved = true;
	}
}
// IMPORTANT!!! You need to save the record to make the new rank value permanent
if (moved) {
  sys.data.save(record);
}