nlapiSearchRecord Sending an Error Instead of Just null

606 views Asked by At

I have created a search using nlapiSearchRecord(). When I tried to implement it, instead of just returning null when there are no results I receive the error That search or mass update does not exist. It worked fine on a different account but I can't figure out what is causing the problem now.

The code should search if a record that matches rec_val exists. If it doesn't match then continue the loop. But instead of continuing the loop an error is thrown. I have tried using the info from a previous post here but to no avail. Any ideas?

Here is my code:

for (var i = 0; i < 5; i++){
  var rec_val = 'some value';
  var column = new nlobjSearchColumn('custfield15');
  var filter = new nlobjSearchFilter('custfield15', null, 'is', rec_val);
  var search = nlapiSearchRecord('inventoryitem', null, filter, column);

  if (search) {
    var rec = nlapiLoadRecord('inventoryitem', search[0].getId());                  
    rec.setFieldValue('custitem5', rec_val);
    nlapiSubmitRecord(rec);
    continue;
  }else{  
    nlapiLogExecution('DEBUG', 'Notice:', 'Nothing to Update'); 
  }
}
1

There are 1 answers

1
VicDid On BEST ANSWER

It turns out there was nothing wrong with my code. It just suddenly started working which means it was probably something else that was causing the error.