Restrict the duplicate records when record producer is submitted

Community Alums
Not applicable

HI All, 

 

Having a requirement need to restrict the duplicate record entries in cmdb_model.lis.

 

we are having a Record producer with the fields as below 

1- Model name 

2- Manufacturer

3- category

4- subcategory

 

when one record is inserted with the name i.e., Name- TF656(free text), Manufacturer - Dell(reference), category - computer(reference), Sub category - Laptop(reference)

 

then again if we try to insert the record withe same name, it should update the record. 

 

Any suiggestions. 

 

3 REPLIES 3

Eswar Chappa
Mega Sage
Mega Sage

Hi @Community Alums write an an Before business rule with insert operation on "cmdb_model" table.In the script just GlideRecord the "cmdb_model" table by querying the "Name" field. If you found any record Just update the GlideRecord Object and abort the insert action an insert an info message for the updation of the existing record in the "cmdb_model" table.

Jonathan Ting
Tera Guru

You could create a client script on the record producer for when that field changes. Have it call a script include using glide ajax, which will contain a function to do a glide record look up for any duplication and return the information you need back to the record producer.

SwarnadeepNandy
Mega Sage

Hello @Community Alums,

 

To restrict the duplicate record entries in the cmdb_model table, you can use the Identification and Reconciliation (IRE) module, which provides a centralized framework for identifying and reconciling data from different data sources. It helps maintain the integrity of the CMDB by preventing duplicate CIs and updating existing CIs with the latest information.

The IRE module uses identification rules to match incoming data with existing CIs based on certain attributes, such as model name, manufacturer, category, and subcategory. If a match is found, the IRE module updates the existing CI with the incoming data. If no match is found, the IRE module creates a new CI with the incoming data.

To use the IRE module for your requirement, you will need to do the following steps:

  • Create an identification rule for the cmdb_model table that specifies the attributes that you want to use for matching, such as model name, manufacturer, category, and subcategory. You can use the Configuration > Identification/Reconciliation > Identification Rules module to create and manage identification rules.
  • Create a transform map for your record producer that maps the fields from your record producer to the fields in the cmdb_model table. You can use the System Import Sets > Load Data > Transform Maps module to create and manage transform maps.
  • In your transform map, enable the Run transform script option and add a script that calls the IRE API to identify and reconcile the incoming data with the existing CIs in the cmdb_model table. You can use the GlideRecord API and the IdentificationEngine API to access and manipulate data in ServiceNow.

Here is an example of a transform script that you can use or modify for your purpose:

 

// Get the source record from the record producer
var source = source.u_model_name + ',' + source.u_manufacturer + ',' + source.u_category + ',' + source.u_subcategory;

// Get the target table name
var targetTable = 'cmdb_model';

// Get the identification rule name
var identificationRule = 'Model Identification Rule';

// Create a new GlideRecord object for the target table
var gr = new GlideRecord(targetTable);

// Call the identify method of the IdentificationEngine API to identify and reconcile the source record with the target table using the identification rule
var sysId = IdentificationEngine.get().identify(source, targetTable, identificationRule);

// Check if a sysId is returned
if (sysId != null) {
  // Get the existing CI record by sysId
  gr.get(sysId);
  // Update the CI record with the source record data
  gr.model_name = source.u_model_name;
  gr.manufacturer = source.u_manufacturer;
  gr.category = source.u_category;
  gr.subcategory = source.u_subcategory;
  // Save the changes
  gr.update();
} else {
  // Create a new CI record with the source record data
  gr.initialize();
  gr.model_name = source.u_model_name;
  gr.manufacturer = source.u_manufacturer;
  gr.category = source.u_category;
  gr.subcategory = source.u_subcategory;
  // Insert the new record
  gr.insert();
}

 

 

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy