NetSuite / Suitescript - Why does this Validate Fi

2019-05-07 20:30发布

问题:

My script is entering into an infinite loop and I have no idea why. I am running this on validate field and I am preventing a change to the field if another vendor bill exists with the same reference number, forcing the user to change the "Reference Number" to be unique. Here is my code:

function validateField(type, name) {

    if (uniqueReferenceNum(type, name) === false) {

        return false;
    }

return true;
}


function uniqueReferenceNum(type, name) {

if (name !== 'tranid') {

    return true;
}

var tranID = nlapiGetFieldValue('tranid');
var vendor = nlapiGetFieldValue('entity');
var vendorName = nlapiGetFieldText('entity');

var filters = new Array();
var columns = new Array();

filters[0] = new nlobjSearchFilter('entity', null, 'is', vendor);
filters[1] = new nlobjSearchFilter('tranid', null, 'is', tranID);
filters[2] = new nlobjSearchFilter('mainline', null, 'is', 'T');

columns[0] = new nlobjSearchColumn('internalid');

results = nlapiSearchRecord('vendorbill', null, filters, columns);

if (!results) {

    return true;

}


alert("There is already a vendor bill with reference # " + tranID + " for " + vendorName + ". Please verify and change the reference number before continuing.");
return false;
}