// set externalid/listingid if we're on a new record or it is empty for some reason
if (newRec.getFieldValue('externalid') == '') {
	// set listing id
	var listingId = getNextListingId();
	nlapiSubmitField(nlapiGetRecordType(), nlapiGetRecordId(), 'externalid', listingId.toString()); // external id can't be set in the standard way
}