```if (parameters.in_test_mode == 'F') {       var...
# suitescript
g
Copy code
if (parameters.in_test_mode == 'F') {
      var filtersPO = []

      filtersPO.push(search.createFilter({
        name: 'otherrefnum', //PO # on Sales Order
        operator: 'is',
        values: order.poNumber
      }));
      filtersPO.push(search.createFilter({
        name: 'entity', //customer id
        operator: 'is',
        values: parameters.customer_id
      }));
      var tranid = ''
      var entity = ''
      var srExisting = ''

      srExisting = SEARCH.create({
        type: record.Type.SALES_ORDER,
        filters: filtersPO,
        columns: ['tranid', 'entity']
      })
      srExisting.run().each(function (result) {
        tranid = result.getValue({
          name: 'tranid'
        })
        entity = result.getValue({ name: 'entity' })
      })
      log.debug('tranid: ' + tranid)
      log.debug('entity: ' + entity)

      if (tranid !== '') {
        log.debug(
          'Order with PO Number: ' +
            order.poNumber +
            ' is already created in Netsuite with Order #: ' +
            tranid
        )
        return
      }
    }
I am trying to prevent duplicate sales from being created. FOr some reason the same tranID keeps returning, Any advice?
b
whats the log of
Copy code
log.debug('filtersPO', filtersPO)
in general, be weary of those transaction id/number filters
some of them are actually numbers and using string type filters like
is
will break them
netsuite silently ignores them, which means you only have the entity filter
my recommendation is to create the search in the ui first, then load the search in script and take a look at the search filters
an alternative would be to use the NetSuite: Search Export
g
"some of them are actually numbers and using string type filters like 
is
  will break them"
That was it
is changed it to equalto - it's a shame it doesn't error