NetSuite / Suitescript - Why does this Validate Field script introduce an infinite loop?

My script goes into an endless loop and I have no idea why. I run this on the validate field, and I discourage the change in the field if there is another vendor account 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;
}

      

+3


source to share





All Articles