How to call 'stored procedure'(of an SQL database), from ServiceNow script include?

Gopika P S
Mega Contributor

How to call 'stored procedure'(of an SQL database), from ServiceNow script include?

5 REPLIES 5

Prathmeshdagade
Mega Guru


Call the Stored Procedure via REST API (Recommended)
You can call a stored procedure through a REST API using a Script Include.

Example: Script Include

 


var CallStoredProc = Class.create(); CallStoredProc.prototype = { initialize: function () {}, execute: function (param1, param2) { var r = new sn_ws.RESTMessageV2('StoredProc_API', 'post'); r.setStringParameterNoEscape('param1', param1); r.setStringParameterNoEscape('param2', param2); var response = r.execute(); return response.getBody(); }, type: 'CallStoredProc' };

 

Use MID Server with JDBC (When REST Is Not Available)
If calling the stored procedure via REST is not an option:

Use a MID Server

Create a JDBC Probe or Scripted JDBC Activity

Execute the stored procedure from the MID Server

Conceptual Example:

 


EXEC dbo.my_stored_procedure @Param1 = ?, @param2 = ?

Use IntegrationHub JDBC Spoke (If Licensed)
If you have IntegrationHub Pro:

Configure a JDBC Connection

Use JDBC Query / Stored Procedure actions

Call them from Flow Designer or Subflows

Optionally trigger the flow from a Script Include
If this response proves useful, please mark it as Accept as Solution and Helpful. Doing so benefits both the community and me.