The CreatorCon Call for Content is officially open! Get started here.

Syncing Two tables with data upon Insert /update.

Mrman
Tera Guru

Hi All,

Can some one please guide me on how to sync two tables upon insert and update of records in one table.

To be more precise I have a custom table(u_maximo_cmdb_ci) created for storing the Configuration Item data from a 3rd party tool. This custom table is not extending any table.

There is another custom table(u_maximo_2_cmdb_integration_table) created for transforming only specific CI data based on some mappings and for that we are building Transform scripts.

Now we want the exact copy of data from u_maximo_cmdb_ci   TO   u_maximo_2_cmdb_integration_table and "u_maximo_2_cmdb_integration_table" should be always in sync with "u_maximo_cmdb_ci " and same records need to be created in "u_maximo_2_cmdb_integration_table" when something is inserted or updated in "u_maximo_cmdb_ci ".

Though a Record is Updated in u_maximo_cmdb_ci it has to do an insert of new record into "u_maximo_2_cmdb_integration_table" because we are running a Transform automatically from there.

We have written the below , but this only does the insert for single record , though I did for 3 to 4 records at a time.

I have written the below Business rule and Script include to do an insert for any insert and update in my 1st Custom table. This is only Inserting a Single record even though I am updating 3 records at a time manually in my 1st Custom table. Please suggest.

Business rule:

===========

When To Run: After   , Insert, Update.

(function executeRule(current, previous /*null when async*/) {

  gs.log("Table Sync BR");

  var insert = new MaximoSyncUtil().insert(current);

  })(current, previous);

Script Include:

==========

var MaximoSyncUtil = Class.create();

MaximoSyncUtil.prototype = {

  initialize: function() {

  },

  insert:function(current){

  gs.log("into syncscript");

  var maximo = new GlideRecord('u_maximo_2_cmdb_integration_table');

  maximo.initialize();

  maximo.u_ciname = current.u_ciname;

        maximo.u_cinum = current.u_cinum;

  maximo.u_address = current.u_address;

  maximo.u_backup_class = current.u_backup_class;

  maximo.u_build_type = current.u_build_type;

  maximo.u_ccipersongroup = current.u_ccipersongroup;

  maximo.u_changedate = current.u_changedate;

  maximo.u_cilocation = current.u_cilocation;

  maximo.u_city = current.u_city;

  maximo.u_ci_managed_by = current.u_ci_managed_by;

  maximo.u_ci_server_type = current.u_ci_server_type;

  maximo.u_cmdb_class_name = current.u_cmdb_class_name;

  maximo.u_comment = current.u_comment;

  maximo.u_customernum = current.u_customernum;

  maximo.u_description = current.u_description;

  maximo.u_environment = current.u_environment;

  maximo.u_hierarchypath = current.u_hierarchypath;

  maximo.u_hostname = current.u_hostname;

  maximo.u_ipaddress = current.u_ipaddress;

  maximo.u_manufacturer = current.u_manufacturer;

  maximo.u_model = current.u_model;

  maximo.u_personid = current.u_personid;

  maximo.u_postalcode = current.u_postalcode;

  maximo.u_primary_affected_country = current.u_primary_affected_country;

  maximo.u_primary_financial_country = current.u_primary_financial_country;

  maximo.u_serialnum = current.u_serialnum;

  maximo.u_servicetype = current.u_servicetype;

  maximo.u_status = current.u_status;

  maximo.insert();

  },

type: 'MaximoSyncUtil'

};

8 REPLIES 8

Yes if I do single update BR gets trigerred and inserts that record in my 2nd Custom table and Transform runs. However If I do multiple updates , only single record gets inserted.


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

OK, lets take it step by step. If you run multiple updates there should be 1 insert per update, so is the BR triggered in that case for each update? You have a gs.log in your BR so you can verify if it was triggered for each update (maybe add in the gs.log also the sys_id of the record you're updating so we can see if the BR is triggered correctly)


We will focus on the transform later.


Hi Sergiu,



Even if I am   doing update fro 3 records in logs there is only one entry for Business rule. and also noticed when updating the value for 3 records only 1 gets saved , when I doing like this.



Please suggest.


find_real_file.png



find_real_file.png


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

So your problem is that updating 3 records is not happening from what I understand. It seems only 1 update is done.


Can you try manually to update each record rather than using multiple updates? In that case BR should be triggered for each one.