- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 10:50 PM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 10:59 PM
HI @abed123 ,
I trust you are doing great.
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.
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 10:59 PM
HI @abed123 ,
I trust you are doing great.
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.
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 01:26 AM
Hi Amit,
Thanks for the inputs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 11:15 PM