4

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;
}
Zain Shaikh
  • 6,013
  • 6
  • 41
  • 66
bluejay92
  • 161
  • 6
  • 21
  • 3
    NetSuite has confirmed that this is a Google Chrome 57 defect - this script works in all other browsers. – bluejay92 Apr 13 '17 at 15:08
  • This answer is right, could you please put the source of that information? It tested my validate field function and it works fine in others browser, I was trying in Google Chrome 58 it does not work properly. – Emerson Minero Jun 02 '17 at 16:45
  • @bluejay92 Can you turn that comment into an answer and mark it as accepted? – Adam Jan 31 '21 at 07:39

1 Answers1

0

For those still facing this issue, you can set the field in question - in this case, Reference Number - to a 'falsy' value such as an empty string. Only return false after checking that the field contains a 'truthy' value. Then display the alert or dialog to the user. This should break the validation loop.