Merge Duplicate Customer Using script

Solution

To merge the duplicate customers through script, use N/task module. Initially search for duplicate records using search.duplicates. This search is working based on the duplication set up on the NetSuite account. You can find duplicate records based on a field or internal id.

let cusSearch = search.duplicates({
                    type: search.Type.CUSTOMER,
                    fields: {
                        "email": "test@abc.com"
                    }
                });
//The search results will be all the records having this same email id.
let cusTask = task.create({
                          taskType: task.TaskType.ENTITY_DEDUPLICATION
                      })
                      cusTask.entityType = task.DedupeEntityType.CUSTOMER;
                      cusTask.dedupeMode = task.DedupeMode.MERGE;
                      cusTask.masterSelectionMode = task.MasterSelectionMode.SELECT_BY_ID
                      cusTask.masterRecordId = 978; //Internal ID of the primary record. Here you can use search results.
                      cusTask.recordIds = ['1112']; // Internal ID of duplicates. Here you can use search results.
                      let taskId = cusTask.submit();

This will merge record ‘1112’ to the ‘978’ including the transactions and will delete the duplicate record

Leave a comment

Your email address will not be published. Required fields are marked *