Saturday, June 22, 2019

Show Alert and prevent Save when Duplicate Customer record is created

With Duplicate Detection Feature the users are notified of potential duplicates upon record creation.
When creating a new record and entering matching data in fields that are set up as duplicate criteria, a warning is shown at the top of the page with a link to the potential duplicates.
Although NetSuite can detect these duplicates, it does not prevent a new record from being saved.

Use case:
Prevent Duplicate Customer record creation by showing a popup message.

Create a User Event Script with Save Record Function that would check if there are any records already existing with these details and show a popup message to prevent from saving.

  1. Script code example:
    function detectDuplicate_OnSave(){var fldMap = new Array();var email = nlapiGetFieldValue('email');fldMap['email'] = email; var duplicateRecords = nlapiSearchDuplicate( 'customer', fldMap ); 	if (duplicateRecords != null) 	{		alert('Record cannot be saved, duplicate detected');		return false;    }else 	return true;}
  2. Create the Client Script record in NetSuite through Customization > Scripting > Scripts > New > Client Script.
    - Scripts tab: select the Script File = the name of the script you have uploaded in step 1 and in Save Record Function = detectDuplicate_OnSave
    - Deployments tab: Applies To = Csutomer, Status = Released, Select Audience

For more information about Client Scripts please visit SuiteAnswers Article 19194 Running Scripts in NetSuite Overview .

DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.

Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

No comments:

Post a Comment