trying to customize ire error messages

jthomsen
Tera Contributor

Hi, I´m trying to change the IRE error message for my customer because they need the end-users to understand what the error is. I have created the following script include: 

var IREErrorMessageHandler = Class.create();
IREErrorMessageHandler.prototype = {
initialize: function() {
},

processCI: function(sourceRecord, ciClass, dataSource) {
var cmdbUtil = new CMDBTransformUtil();
cmdbUtil.setDataSource(dataSource || "ImportSet");

// Run IRE processing
cmdbUtil.identifyAndReconcile(sourceRecord, null, gs);

// Check for errors
if (cmdbUtil.hasError()) {
var defaultError = cmdbUtil.getError();
var customMessage = this._getFriendlyMessage(defaultError, sourceRecord);
return {
isError: true,
message: customMessage || defaultError,
defaultMessage: defaultError
};
}

return {
isError: false,
message: "CI processed successfully for '" + (sourceRecord.u_name || "unknown") + "'.",
sysId: cmdbUtil.getOutputRecordSysId()
};
},

_getFriendlyMessage: function(defaultError, sourceRecord) {
var ciName = sourceRecord.u_name || "unknown CI";
var serial = sourceRecord.u_serial_number || "none";

if (defaultError.indexOf("RECLASSIFICATION_NOT_ALLOWED") !== -1) {
return "Cannot change the type of '" + ciName + "' (Serial: " + serial + "). The CI type is fixed once set. Please create a new CI.";
}
if (defaultError.indexOf("MULTIPLE_DUPLICATE_RECORDS") !== -1) {
return "Multiple existing CIs match '" + ciName + "' (Serial: " + serial + "). Please clarify the data to avoid conflicts.";
}
if (defaultError.indexOf("DUPLICATE_PAYLOAD_RECORDS") !== -1) {
return "The import contains duplicate entries for '" + ciName + "' (Serial: " + serial + "). Please remove duplicates.";
}
if (defaultError.indexOf("INVALID_INPUT_DATA") !== -1) {
return "Invalid data for '" + ciName + "' (Serial: " + serial + "). Please check fields like location or class.";
}
if (defaultError.indexOf("MISSING_MATCHING_ATTRIBUTES") !== -1) {
return "Missing required fields for '" + ciName + "' (Serial: " + serial + "), such as name or serial number.";
}
// Implicitly return undefined for non-matching errors
},

type: "IREErrorMessageHandler"
};

 

I can´t use a transform script to use the script include because the imports are all done using integrationhub etl. Is anything wrong with my script include and what would be the best way to trigger it, when the actual ire error occurs on an import?

0 REPLIES 0