onBefore transform script for CMDB identification NOT WORKING

Nisha30
Kilo Sage

Hi,

Can anyone suggest what have to be rectified here i am using as the normal code snippet in onBefore transform script but seems it ignores all time . When i dont use ignore== true in below code it always inserts and not following IRE rule. There is NO Coalesce set as True. Can anyone help please. Thanks

 

Transform script : onBefore

 

(function runTransformScript(source, map, log, target ) {
log.info("Status Log ImpSet");
var cmdbUtilIRE = new global.CMDBTransformUtil();
cmdbUtilIRE.setDataSource('ImportSet');
cmdbUtilIRE.identifyAndReconcileEnhanced(source, map, log);
ignore = true;

if (cmdbUtilIRE.hasError()) {
var errorMessage = cmdbUtilIRE.getError();
log.info('Error: ' + errorMessage);
log.error(errorMessage);
} else {
log.info('IE Output Payload: ' + cmdbUtilIRE.getOutputPayload());
log.info('Imported CI: ' + cmdbUtilIRE.getOutputRecordSysId());
}

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

 

 

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @Nisha30 ,

you did not given any specific condition when script needs to ignore. so every time it will return ignore =true. 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

3 REPLIES 3

-O-
Kilo Patron
Kilo Patron

The usage paradigm in case of transform maps with IRE is to actually cancel the transformation of all rows.

The only "role" played here by the transform map is to go through all the records in the import set transformed, call the IRE API for each row and than actually to cancel the transformation of the row. Therefore there is no need for coalesce either.

Consider that the transformation of one row might actually result in a CI created, updated or multiple CI being created or updated. So relating one import set row to a target row can be pretty problematic.

But if you are sure all rows in the import set will create or update a specific class, you could move the IRE API call into a sys_id scripted coalesce field and analyze the data returned by the IRE API call and based on that set the target record.

In order to coalesce based on scripts, one has to create a scripted field map for (target) sys_id and in that script return the sys_id of the matched record or -1 if a new record is to be created. SN in docs page Updating records using coalesce  describes it as "Conditional coalesce". The reason for moving the script from Before transform event script into a Scripted field map is because the latter (coalesce scripts) are actually executed even before the former (event scripts). In other words Scripted field maps that have as target field sys_id and are marked as coalesce "become" a special kind of Scripte field map.

Pavankumar_1
Mega Patron

Hi @Nisha30 ,

you did not given any specific condition when script needs to ignore. so every time it will return ignore =true. 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Pavankumar_1
Mega Patron

Hi @Nisha30 ,

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar