Narsing1
Mega Sage

Servicenow provides various options to get the data from different discovery sources. The data flows into Servicenow via different applications like 3rd Party Applications,  Excel imports and places into CMDB Tables.

 

While doing these activities, it is always better to use IRE Engine to insert/update records into CMDB Tables because it has all the features to determine which discovery source can update via Reconciliation Rules (or) determine whether a record can be inserted / updated via Identification Rules  and so on.

 

The process to import this kind of data starts with creating Data Source, Field Mapping & Transform Scripts.  Finally some integrations requires a Scheduled Data Import. Regular way of scripting the transform is cumbersome and lot of maintenance work is required even for a small changes in IRE Rules.  To address this, we have an OOTB class called "CMDBTransformUtil" that helps in determining inserting/updating the records properly and ensure to minimize the creation of duplicate entries.

 

Example

Table - Company Resources 

Identification Rules are like this

Narsing1_0-1690470662170.png

Reconciliation Rules are like this

Narsing1_0-1690529727820.png

 

The below data from an Excel sheet needs to be imported

Narsing1_1-1690471173925.png

For the above table, the Data Source, Transform Map & Transform Script is configured like this

Data Source#

Narsing1_2-1690471232359.png

Transform Map#

Narsing1_3-1690471270229.png

Transform Script#

Narsing1_4-1690471321150.png

Now, Load all records from Data Source => Go to the Import Set ==> Transform.  You can observe the records in the Table like this

Narsing1_5-1690471623321.png

When it comes to updating of these records, Since we are using CMDBTransformUtils, it update records using IRE Engine and we don't need to write any unnecessary logics within the Transform Scripts.

Note:  The Low Priority is ACC-Visibility & the High Priority taken as "ABC Application"

ABC ApplicationACC-Visibility
Can update Name, Serial Number, Description, Location, ManufacturerCan only updates Description field

 

Now, lets see how a row will update based on the DataSource/Discovery Source.  Here is the code for your reference.

 

 

 

OnBefore Script# using ABC Application as Data Source

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
	// Add your code here
	var ctu = new CMDBTransformUtil();
	ctu.setDataSource("ABC Application");
	//#commented#ctu.setDataSource("ACC-Visibility");
	ctu.identifyAndReconcileEnhanced(source, map, log);
	ignore = true;
	
if (ctu.hasError()) {
        var errorMessage = ctu.getError();
        log.error(errorMessage);
} else {
        log.info('IE Output Payload: ' + ctu.getOutputPayload());
        log.info('Imported CI: ' + ctu.getOutputRecordSysId());
}
})(source, map, log, target);

 

 

 

 

 

Existing Record from Company Resources Table

Narsing1_1-1690528231143.png

I have changed the name & description as below from the Import set Rows

Narsing1_0-1690547902119.png

After Executing the Transform again, the row updates like this.  Since it was using "ABC Application" as Data Source, it updated both the fields after matching rules.

Narsing1_0-1690547709879.png

If you change the Datasource to "ACC-Visibility" in transform script and execute the transform, since it is supposed to update only Description field, the remaining fields update will skip like this.

Narsing1_0-1690548544808.png

Narsing1_0-1690559566233.png

 

Important:

  • It is always better not to toggle "Apply to all attributes" when you create a Reconciliation Rule. Rather select the fields independently.
  • "Update with null" needs to be selected in case if would like to update with a null value when the field value is not empty.  
  • If you would like to update a value when it is empty with Low Priority Reconciliation Rule, 
    • Make sure the "CMDB Properties==>Identification/Reconciliation Properties ==> Allow the update of an empty field by a lower priority data source" to true.
  • Use the "Identification Simulation" when things are not working to see how the IRE Engine behaves of a specific record.
  • Use "SNC.IdentificationEngineScriptableApi" in case if you would like to completely skip the Data source, Transform and go with your own way of importing the data.  This can be useful when you are dealing with REST Outbound to get the data via API.
  • You may also think of creating a "Data Stream" via Flow Designer when you deal with REST Outbound to get the data via API.

Please feel free to add your comment/any other guide lines.

 

Thank you,

Narsing

 

 

Comments
Mark Wood
Tera Contributor

Helpful Thank You @Narsing1 

snowdev8
Tera Expert

Should we select Run Business Rules on the TMap?

Narsing1
Mega Sage

It depends on case to case.  Normally, on these

  • Is the TMap doing huge updates to the table? - Don't run BR
  • Is the TMap needs to perform any other operations apart from updating/inserting records to the target table? Yes run BR

 

Version history
Last update:
‎07-28-2023 09:33 AM
Updated by:
Contributors