Transfrom script to create de duplciation task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 04:23 AM
1) I have created a data source and attached excel. There are 2 columns ci_number_1 & ci_number_2 which form a pair of config_item_id.
2) I am using this in a transform map and need to create a onafter transform script which will fetch the sys_id of the above pair and then create de-duplication task using them. And map both the config_ci_id under related list Duplicate CI & Depend on CI respectively.
I have written below on-after transform script which is creating the de-dup task but not mapping the ids in related list. Need help in script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var ci1_sys_id = "";
var ci2_sys_id = "";
// Lookup for CI 1
if (source.ci_number_1) {
var ci1 = new GlideRecord('cmdb_ci');
ci1.addQuery('u_config_item_id', source.ci_number_1);
ci1.query();
if (ci1.next()) {
ci1_sys_id = ci1.getUniqueValue();
}
}
// Lookup for CI 2
if (source.ci_number_2) {
var ci2 = new GlideRecord('cmdb_ci');
ci2.addQuery('u_config_item_id', source.ci_number_2);
ci2.query();
if (ci2.next()) {
ci2_sys_id = ci2.getUniqueValue();
}
}
// If both found, create the de-duplication task
if (ci1_sys_id && ci2_sys_id) {
var sysIDs = [ci1_sys_id, ci2_sys_id];
var dupTaskUtil = new global.CMDBDuplicateTaskUtils();
var deDupTaskID = dupTaskUtil.createDuplicateTask(sysIDs);
log.info("Created Duplicate Task ID: " + deDupTaskID);
} else {
log.warn("CI not found for row: " + source.sys_id);
}
})(source, map, log, target);
NOTE - I read that "
script only set those fields if it knows what the main CI is, and/or via IRE. If you just mark the CIs with a de-dupe task, it doesn't know what is the main CI so it can't populate it: Duplicate CIs remediation
#transform script, #de-duplication task, #cmdb

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 06:31 AM
Hi,
Is the above is a modified code or actual code from your system? Normally the fields in source table prefix with u_ as all fields are custom field in import set table.
If this is the same code you are using, then try the below code and let me know the result
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var ci1_sys_id = "";
var ci2_sys_id = "";
// Lookup for CI 1
if (source.u_ci_number_1) {
var ci1 = new GlideRecord('cmdb_ci');
ci1.addQuery('u_config_item_id', source.u_ci_number_1);
ci1.query();
if (ci1.next()) {
ci1_sys_id = ci1.getUniqueValue();
}
}
// Lookup for CI 2
if (source.u_ci_number_2) {
var ci2 = new GlideRecord('cmdb_ci');
ci2.addQuery('u_config_item_id', source.u_ci_number_2);
ci2.query();
if (ci2.next()) {
ci2_sys_id = ci2.getUniqueValue();
}
}
// If both found, create the de-duplication task
if (ci1_sys_id && ci2_sys_id) {
var sysIDs = [ci1_sys_id, ci2_sys_id];
var dupTaskUtil = new global.CMDBDuplicateTaskUtils();
var deDupTaskID = dupTaskUtil.createDuplicateTask(sysIDs);
log.info("Created Duplicate Task ID: " + deDupTaskID);
} else {
log.warn("CI not found for row: " + source.sys_id);
}
})(source, map, log, target);
Palani