Syncing Two tables with data upon Insert /update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 01:52 AM
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'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 01:55 AM
You want probably one function for inserts and another function for updates, rather than only one function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 02:00 AM
Hi Sergiu,
Actually I do not want to Update , I only want to insert even though if something is updated in my 1st table.
Because , I am running Transform to a Target table from my 2nd Custom table.
I want to insert a new record every time and setting the the mode to Synchromous using a different business rule so Transform runs immediately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 02:22 AM
Hi Sergiu,
Could you please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 02:51 AM
If you just do a single update, is the BR even triggered?