Tuesday, September 25, 2018

Search for records that contain a specific text/value on the PO# field (id: otherrefnum)

To retrieve all records that contains a substring of a specific text/value on the PO# field (id: otherrefnum), simply using "nlobjSearchFilter('otherrefnum', null, 'contains', text)" does not seem to work. It returns all the records as if no filter has been applied. Using "equalto" works but this would match the entire field value in the PO# field.
 
The solution is to use "poastext" instead of "otherrefnum". Refer to sample code below.

function searchOtherRefNum()
{
  var filters = new Array();
  filters[0] = new nlobjSearchFilter('poastext', null, 'contains', 'ABC'); //Change the 'ABC' string as needed
  filters[1] = new nlobjSearchFilter('mainline', null, 'is', 'T');

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

  var results = nlapiSearchRecord('salesorder', null, filters, columns);

  if(results != null && results.length > 0){
    nlapiLogExecution('debug','Search Results: ', results.length);
    for ( var i = 0; results != null && i < results.length; i++ )
    {
     var searchresult = results[ i ];
     var recOrder = searchresult.getValue('internalid');

     nlapiLogExecution('debug','recOrder',recOrder );
    }
  }
}

No comments:

Post a Comment