Overview
In any business, managing customer records efficiently is crucial for maintaining data integrity and optimizing operations. However, duplicate customer records can lead to confusion, errors, and inefficiencies. In NetSuite SuiteScript provides powerful tools to automate tasks and streamline processes. One such tool is the task.TaskType.ENTITY_DEDUPLICATION function, which can be utilized within scripts to deduplicate customer records effectively.
In this technical guide, we’ll explore how to leverage SuiteScript to implement the deduplication of customer records in NetSuite, specifically focusing on using the task.TaskType.ENTITY_DEDUPLICATION function within the afterSubmit method of a user event script.
Understanding task.TaskType.ENTITY_DEDUPLICATION
Before diving into the implementation details, let’s grasp the essence of task.TaskType.ENTITY_DEDUPLICATION. This function is designed to identify and merge duplicate records of a particular entity type, in our case, customer records. It automates the process of detecting duplicates based on predefined criteria and consolidates them into a single, accurate record.
Prerequisites
To implement the deduplication of customer records in NetSuite, ensure the following prerequisites are met:
- Access to NetSuite Administrator role or equivalent permissions.
- Basic understanding of SuiteScript, particularly user event scripts.
- Familiarity with the NetSuite UI and scripting environment.
Implementation Steps
1. Create a User Event Script
Begin by creating a new SuiteScript file within your NetSuite account. Choose the “User Event Script” type and set the appropriate triggers, such as afterSubmit, to execute the deduplication process after a customer record is submitted.
2. Implement the afterSubmit Method
Within the user event script, implement the afterSubmit method. This method will be responsible for triggering the deduplication process using the task.TaskType.ENTITY_DEDUPLICATION function.
- Identify that this record is a duplicate of another record using some script logic prior to executing the deduplication methods.
- Assign the task type
- Assign the entity type for the de-duplication operation.
- Assign the deduplication Master Selection Mode:
- CREATED_EARLIEST – Merges records into the entity record that was created first.
- MOST_RECENT_ACTIVITY – Merges records into the one containing most recent updates.
- MOST_POPULATED_FIELDS – Merges records into the one with the most field values.
- SELECT_BY_ID – Allows you to select the explicit ids of the master and record and duplicates. If you use this option for the master selection mode, set the ID of the master record with EntityDeduplicationTask.masterRecordId.
- Assign the masterRecordId value.
- Assign the dedupeTask.recordIds as an array or you can use the search.duplicates(options) method in the N/search Module to find the duplicate records. In our example, we are doing a real time deduplication when a record is created in the system that contains a duplicate, so we will not use the search option.
Example Code:
var masterRecordId //This is assigned the entity id of the record to be merged into.
var duplicateRecordId //This is assigned the entity id of the duplicate record to be merged
var dedupeTask = task.create({taskType: task.TaskType.ENTITY_DEDUPLICATION});
dedupeTask.entityType = task.DedupeEntityType.CUSTOMER;
dedupeTask.dedupeMode = task.DedupeMode.MERGE;
dedupeTask.masterSelectionMode = task.MasterSelectionMode.SELECT_BY_ID;
dedupeTask.masterRecordId = masterRecordId
dedupeTask.recordIds = [masterRecordId, duplicateRecordId];
var dedupeTaskId = dedupeTask.submit();
log.debug('dedupeTaskId', dedupeTaskId);
Conclusion
Implementing the deduplication of customer records in NetSuite using SuiteScript can significantly enhance data quality and streamline business processes. By leveraging the task.TaskType.ENTITY_DEDUPLICATION function within a user event script, you can automate the detection and consolidation of duplicate customer records, thereby improving operational efficiency and accuracy.
About Us
We are NetSuite solutions providers with 30+ years of combined experience. We specialize in implementation, optimization, integration, rapid project recovery and rescue as well as custom development to meet any business need. Although every business is unique, with 40+ NetSuite clients over the last 5+ years our team has most likely seen your challenge or created a similar solution. If you would like more information on NetSuite or just have questions on your project, feel free to contact us Here.