Imported Record - Fetch
Retrieve a ServiceNow staging table record using SQL Server
- See SQLHTTP easy setup for ServiceNow
- See API Call documentation for parameter values and other information
- Create the stored procedure documented below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
CREATE PROCEDURE usp_ServiceNow_Imported_Data_Fetch( @Profile nvarchar(100), @TableName varchar(MAX), @Sys_id varchar(50), @Response nvarchar(MAX) OUTPUT, @StatusCode int OUTPUT, @StatusDescription nvarchar(MAX) OUTPUT) AS DECLARE @URL nvarchar(MAX) DECLARE @QueryString varchar(MAX) DECLARE @UserName nvarchar(4000) DECLARE @Password nvarchar(4000) DECLARE @HTTPSessionID uniqueidentifier SET @URL = SQLHTTP.net.AuthParam(@Profile, 'Domain') EXEC SQLHTTP.net.UrlBuilder @URL OUTPUT, @Profile, 'api', 'now', 'import', @TableName, @Sys_id EXEC SQLHTTP.net.HTTPSession @HTTPSessionID OUTPUT SET @UserName = SQLHTTP.net.AuthParam(@Profile, 'UserName') SET @Password = SQLHTTP.net.AuthParam(@Profile, 'Password') EXEC SQLHTTP.net.BasicAuthHeader @HttpSessionID, @UserName, @Password EXEC SQLHTTP.net.HTTPRequest @HttpSessionID, @URL = @URL, @Method = 'GET', @Accept = 'application/xml', @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT, @Response = @Response OUTPUT GO |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) EXEC usp_ServiceNow_Imported_Data_Fetch @Profile = 'My ServiceNow', @TableName = 'imp_user', @Sys_id = 'a910f1ef0ff2030041ea06ace1050e1f', @Response = @Response OUTPUT, @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT IF @StatusCode >= 400 EXEC SQLHTTP.net.RaiseHttpError @StatusCode, @StatusDescription, @Response ELSE BEGIN DECLARE @X xml SET @X = CONVERT(xml, CONVERT(varchar(MAX), @Response)) --The XPath syntax below was easily generated by executing the following commands: --EXEC SQLHTTP.net.XQueryHelper @X --and then executing: --EXEC SQLHTTP.net.XQueryHelper @X, 'response' SELECT T.C.value(N'import_set[1]', N'nvarchar(MAX)') AS [import_set] ,T.C.value(N'staging_table[1]', N'nvarchar(MAX)') AS [staging_table] ,T.C.value(N'result[1]/sys_id[1]', N'nvarchar(MAX)') AS [sys_id] ,T.C.value(N'result[1]/table[1]', N'nvarchar(MAX)') AS [table] ,T.C.value(N'result[1]/display_name[1]', N'nvarchar(MAX)') AS [display_name] ,T.C.value(N'result[1]/display_value[1]', N'nvarchar(MAX)') AS [display_value] FROM @X.nodes(N'/response') T(C) END |
1 2 3 4 5 |
import_set staging_table sys_id table display_name display_value ------------ -------------- ----------------- ---------- -------------- ----------------- ISET0010001 imp_user a910f1ef0ff20... sys_user name John Public |
IMPORTANT DISCLAIMER
CODE/SQL ON THESE PAGES ARE PROVIDED AS-IS AND ARE AVAILABLE FOR ILLUSTRATIVE PURPOSES ONLY.
USERS ARE REQUIRED TO ABIDE BY THE TERMS AND CONDITIONS FOR USING REFERENCED THIRD PARTY WEBSITES AND/OR APIs FROM THEIR RESPECTIVE WEBSITES. WE DO NOT CONDONE ANY VIOLATION OF THIRD PARTY WEBSITES AND/OR APIs TERMS AND CONDITIONS USING OUR SOFTWARE.
USERS SHALL BE SOLELY RESPONSIBLE AND BE SOLELY LIABLE FOR VIOLATION OF ANY RULES SPECIFIED BY THIRD PARTIES FOR USING THEIR WEBSITES AND/OR APIs, OR INFRINGEMENT OF RIGHTS OF SUCH THIRD PARTIES.