Import set IRE

PrishaGorakh
Tera Contributor

i have an transform map script to insert data into corresponding tables now along with this i also want to trigger IRE how can i do so , i tried to change the existing code that but inst working and added a separate code in related lists for this but even this isnt working .

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var classMap = {
"computer": "cmdb_ci_computer",
"server": "cmdb_ci_server",
"unix server": "cmdb_ci_unix_server",
"application software": "cmdb_ci_application_software",
"desktop software": "cmdb_ci_desktop_software",
"database": "cmdb_ci_database"
};

var inputClass = source.u_class_name ? source.u_class_name.toLowerCase().trim() : source.u_class.toLowerCase().trim();
var targetTable = classMap[inputClass];

if (!targetTable) {
log.info("Unknown class: " + inputClass);
return;
}

var ci = new GlideRecord(targetTable);
ci.initialize();

// CASE 1: Computer / Server / Unix Server
if (["computer", "server", "unix server"].includes(inputClass)) {
ci.name = source.u_ci_name;
ci.serial_number = source.u_serial_number;
ci.dns_domain = source.u_domain;
ci.category = source.u_category;
ci.disk_space = source.u_disk_space;
ci.ram = source.u_total_physical_memory;
ci.os = source.u_os;
ci.os_version = source.u_os_versions;

//  Model ID lookup
var modelGR = new GlideRecord('cmdb_model');
modelGR.addQuery('display_name', source.u_model_id);
modelGR.query();
if (modelGR.next()) {
ci.model_id = modelGR.getUniqueValue();
} else {
log.info('Model not found: ' + source.u_model_id);
}
}

// CASE 2: Application Software / Desktop Software
else if (["application software", "desktop software"].includes(inputClass)) {
ci.name = source.u_ci_name;
ci.category = source.u_category;
ci.version = source.u_version;
}

//  CASE 3: Database
else if (inputClass === "database") {
ci.name = source.u_ci_name;
ci.category = source.u_category;
ci.version = source.u_version;
ci.type = source.u_type__f_;
}

// Insert into target class table
ci.insert();

// Skip the default cmdb_ci insert
ignore = true;

})(source, map, log, target);
3 REPLIES 3

AJ-TechTrek
Giga Sage
Giga Sage

Hi @PrishaGorakh ,

 

As per my understanding why it’s not working


* When you do a direct .insert() into a CMDB class table (like cmdb_ci_computer), you bypass the Identification and Reconciliation Engine (IRE).
* IRE needs a structured payload and must be called explicitly via script, transform map, or integration.

How to do it properly: Call IRE in your transform map


Instead of directly inserting the record with .insert(), you should:
* Build an IRE payload
* Use the IdentificationEngine API to process the payload
* Let IRE do the insert/update into the right CMDB tables

 

Modified script:
(function runTransformScript(source, map, log, target /*undefined onStart*/) {
var classMap = {
"computer": "cmdb_ci_computer",
"server": "cmdb_ci_server",
"unix server": "cmdb_ci_unix_server",
"application software": "cmdb_ci_application_software",
"desktop software": "cmdb_ci_desktop_software",
"database": "cmdb_ci_database"
};

var inputClass = source.u_class_name ? source.u_class_name.toLowerCase().trim() : source.u_class.toLowerCase().trim();
var targetTable = classMap[inputClass];

if (!targetTable) {
log.info("Unknown class: " + inputClass);
return;
}

// Build the payload for IRE
var payload = {
items: [{
className: targetTable,
values: {
name: source.u_ci_name,
serial_number: source.u_serial_number,
dns_domain: source.u_domain,
category: source.u_category,
disk_space: source.u_disk_space,
ram: source.u_total_physical_memory,
os: source.u_os,
os_version: source.u_os_versions
}
}]
};

// Lookup model_id if needed
if (["computer", "server", "unix server"].includes(inputClass)) {
var modelGR = new GlideRecord('cmdb_model');
modelGR.addQuery('display_name', source.u_model_id);
modelGR.query();
if (modelGR.next()) {
payload.items[0].values.model_id = modelGR.getUniqueValue();
} else {
log.info('Model not found: ' + source.u_model_id);
}
}
// Add fields for software
else if (["application software", "desktop software"].includes(inputClass)) {
payload.items[0].values.version = source.u_version;
}
// Add fields for database
else if (inputClass === "database") {
payload.items[0].values.version = source.u_version;
payload.items[0].values.type = source.u_type__f_;
}

// Call IRE
var IdentificationEngine = new GlideIdentificationEngine();
var result = IdentificationEngine.createOrUpdateCI(JSON.stringify(payload));

log.info("IRE result: " + result);

// Prevent default insert
ignore = true;

})(source, map, log, target);

 

Explanation of what changed:
* Instead of creating a GlideRecord and inserting directly:
* Build a JSON payload with the needed class and field values
* Call the GlideIdentificationEngine().createOrUpdateCI() method
* This will:
* Respect the identification rules
* Avoid duplicates
* Trigger the reconciliation process
* Populate the CMDB properly

 

My tips on this for you:
* Make sure your Identification Rules are properly configured (e.g., matching on serial_number, name, etc.).
* Always test the payload in lower environments.
* Check syslog and cmdb_ire_error tables if the payload fails.
* Avoid mixing direct .insert() with IRE in the same transform — pick one approach (usually IRE).

 

Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
 
Thank You
AJ - TechTrek with AJ
LinkedIn:- https://www.linkedin.com/in/ajay-kumar-66a91385/
YouTube:- https://www.youtube.com/@learnitomwithaj
ServiceNow Community MVP 2025

Screenshot 2025-07-24 at 9.27.26 PM.png

 if i run this code i get this plus all the records are getting inserted into cmdb_ci table and not the respective tables and also all records are empty 

Screenshot 2025-07-24 at 9.30.47 PM.png

 if i run this code i get this in my logs plus all the records are being inserted into cmdb_ci table instaed of their respective tables and also all the records getting inserted are empty