Updating a staging table before cmdb while populating with discovery

snehakerwal
Kilo Explorer

I am trying to update a staging table before cmdb while using discovery. I need that whenever a new record is created or an update to an existing record is about to be made in cmdb, an onbefore br should run on cmdb and update the staging table and changes on cmdb should be aborted.

I am trying to get the values of all the fields in the cmdb table and then trying to match the fields (by column label) in the staging stable, and if the match is found, value from cmdb field should be populated in the staging   table.

I am using the below code but it is not working. could some one help?

var gr = new GlideRecord('u_cmdb_staging');

gr.addQuery('discovery_source','ServiceNow');

  gr.addQuery('serial_number',current.serial_number);

gr.query();

  if(gr.next()){

  var staging_fields = gr.getFields();

  for (var j = 0; j < staging_fields.size(); j++) {

  var glideElementStaging = staging_fields.get(j);  

  var fields = current.getFields();

  for (var i = 0; i < fields.size(); i++) {

    var glideElement = fields.get(i);

if(glideElement.getLabel() == glideElementStaging.getLabel()){

  glideElementStaging = glideElement;

  gr.update();

  }

}

}}

2 REPLIES 2

surya123
Mega Guru

Any solution u got for this?


Ryan Zulli
ServiceNow Employee
ServiceNow Employee

ServiceNow does not support or recommend the implementation of a staging table.   It is very possible for these tables to get out of sync very quickly, also all updates that Discovery or any tool find are valid and should be updated within the CMDB.



That said you can add a custom checkbox field at the cmdb_ci or device class level called "u_verified" and control what data is presented to your customers using ACL's.   This way if the u_verified box is not checked, only you and the device owner can view that record.   Once its approved then it would be available for everyone to see.



Hope this helps.


Thanks,


-Ryan