Duplicate records are inserting even coalesce field is true

abed123
Tera Contributor

Hi All,

 

We have a transform map that create records in computer table. for name field we have coalesce is true but we could see the duplicate records, could anyone please help on this how to avoid duplicate insertions.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

HI @abed123 ,
I trust you are doing great.

  1. Identify the field or combination of fields in the computer table that should serve as a unique identifier for each record. Let's assume the unique identifier is the 'name' field.

  2. Create a new dictionary entry for the 'name' field in the transform map. In this dictionary entry, set the 'Unique' property to true. This ensures that the 'name' field acts as a unique identifier for the records.

  3. Modify the transform script associated with the transform map to handle duplicate records. Inside the transform script, before inserting a new record, you can check if a record with the same 'name' value already exists in the computer table. If a matching record is found, you can either update the existing record or skip the insertion altogether.

 

(function transformEntry(source, target, map, log, isUpdate) {

  var existingRecord = new GlideRecord('computer');
  existingRecord.addQuery('name', source.name);
  existingRecord.query();

  if (existingRecord.next()) {

    log.info('Duplicate record found. Updating existing record with name: ' + source.name);

  } else {

    target.name = source.name;
  


    target.insert();
    log.info('New record inserted with name: ' + source.name);
  }
})(source, target, map, log, action === 'update');

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

3 REPLIES 3

Amit Gujarathi
Giga Sage
Giga Sage

HI @abed123 ,
I trust you are doing great.

  1. Identify the field or combination of fields in the computer table that should serve as a unique identifier for each record. Let's assume the unique identifier is the 'name' field.

  2. Create a new dictionary entry for the 'name' field in the transform map. In this dictionary entry, set the 'Unique' property to true. This ensures that the 'name' field acts as a unique identifier for the records.

  3. Modify the transform script associated with the transform map to handle duplicate records. Inside the transform script, before inserting a new record, you can check if a record with the same 'name' value already exists in the computer table. If a matching record is found, you can either update the existing record or skip the insertion altogether.

 

(function transformEntry(source, target, map, log, isUpdate) {

  var existingRecord = new GlideRecord('computer');
  existingRecord.addQuery('name', source.name);
  existingRecord.query();

  if (existingRecord.next()) {

    log.info('Duplicate record found. Updating existing record with name: ' + source.name);

  } else {

    target.name = source.name;
  


    target.insert();
    log.info('New record inserted with name: ' + source.name);
  }
})(source, target, map, log, action === 'update');

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi Amit,

 

Thanks for the inputs.

Manmohan K
Tera Sage

Hi @abed123 

 

It might be because the records which are duplicate have empty coalesce field