- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 12:17 AM
We have a requirement of bi-directional integration between SQL database and Servicenow CMDB. Can we run update queries in servicenow data source so that the scheduled load can update the data in SQL DB?
If not, what would be the preferable way to run update queries in this integration?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2020 07:43 AM
high level:
- create data source that points to your sql db, put generic part of sql
dynamic part will be added in script includes
- create script includes (see code sample below)
- create ui action (we using ui action) OR you could create scheduled job to run code from script includes
i did not test this code, but it could be starting point for you
var Asset_Util = Class.create();
Asset_Util.prototype = {
initialize : function() {
this.dtSource= YOUR_DATA_SOURCE_NAME;
this.timeout = 20;
},
executeRemoteQuery:function(assetId){
var queryResults='';
var ds = new GlideRecord("sys_data_source");
ds.addQuery('name', this.dtSource);
ds.query();
if (ds.next()) {
this.midServer = ds.mid_server.getDisplayValue();
this.SQL = ds.sql_statement.toString();
var mid = new GlideRecord("ecc_agent");
mid.addQuery('name', this.midServer);
mid.query();
if (mid.next()) {
var eccQueueId=0;
var sqlSelect = new JDBCProbe(this.midServer);
sqlSelect.setDataSource(ds.sys_id);
var mySQL = this.SQL + " WHERE assetId='"+assetId+"'"; //HERE DYNAMIC PART OF SQL
sqlSelect.setFunction("");
sqlSelect.addParameter("query", "Specific SQL");
sqlSelect.addParameter("sql_statement", mySQL);
eccQueueId= sqlSelect.create();
gs.print(eccQueueId);
}
}
},
type: 'Asset_Util'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 11:25 PM
Yes i need to update data in SQL db from ServiceNow. Could you please provide more details on how i can implement this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2020 07:43 AM
high level:
- create data source that points to your sql db, put generic part of sql
dynamic part will be added in script includes
- create script includes (see code sample below)
- create ui action (we using ui action) OR you could create scheduled job to run code from script includes
i did not test this code, but it could be starting point for you
var Asset_Util = Class.create();
Asset_Util.prototype = {
initialize : function() {
this.dtSource= YOUR_DATA_SOURCE_NAME;
this.timeout = 20;
},
executeRemoteQuery:function(assetId){
var queryResults='';
var ds = new GlideRecord("sys_data_source");
ds.addQuery('name', this.dtSource);
ds.query();
if (ds.next()) {
this.midServer = ds.mid_server.getDisplayValue();
this.SQL = ds.sql_statement.toString();
var mid = new GlideRecord("ecc_agent");
mid.addQuery('name', this.midServer);
mid.query();
if (mid.next()) {
var eccQueueId=0;
var sqlSelect = new JDBCProbe(this.midServer);
sqlSelect.setDataSource(ds.sys_id);
var mySQL = this.SQL + " WHERE assetId='"+assetId+"'"; //HERE DYNAMIC PART OF SQL
sqlSelect.setFunction("");
sqlSelect.addParameter("query", "Specific SQL");
sqlSelect.addParameter("sql_statement", mySQL);
eccQueueId= sqlSelect.create();
gs.print(eccQueueId);
}
}
},
type: 'Asset_Util'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2020 10:04 PM
Thank you for the steps. I will try this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2022 04:11 AM
how to query data from database through SNOW workflow