Saturday, November 3, 2018

Prevent a Duplicate Customer record from being saved in NetSuite

NetSuite's Duplicate Detection & Merge feature  helps you find these duplicate records in NetSuite. Although NetSuite can detect these duplicates, it does not prevent a new record from being saved. A certain use case wherein a user does not want a new Customer record be saved if it is already existing in NetSuite.

To workaround the problem, one can use the combination of  nlapiSearchDuplicate and nlapiCreateError.

nlapiSearchDuplicate will perform a search for duplicate records based on the account's Duplicate Detection configuration. If a record already exists, then an error will be thrown to prevent the record from being saved in NetSuite.

Below is a sample snippet to use that is to be deployed on before submit of  Customer record:

The following example performs a duplicate detection search for all customer records using the "email" field of the currently submitted record.
 

function detectDup(){
var fldMap = new Array();
fldMap['email'] = nlapiGetFieldValue('email');
var duplicateRecords = nlapiSearchDuplicate( 'customer', fldMap );

if (duplicateRecords !=null) {
var err = nlapiCreateError('E500', 'Record cannot be saved, duplicate detected');
   throw err;
    }
}
 
 

No comments:

Post a Comment