Attachments - Fetch
Retrieve ServiceNow attachments metadata 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
CREATE PROCEDURE usp_ServiceNow_Attachments_Fetch( @Profile nvarchar(100), @Sysparm_query varchar(MAX) = NULL, @Sysparm_limit bigint = 10000, @Sysparm_offset bigint = NULL, @Sysparm_read_replica_category varchar(MAX) = NULL, @Sysparm_suppress_pagination_header bit = NULL, @Response nvarchar(MAX) OUTPUT, @StatusCode int OUTPUT, @StatusDescription nvarchar(MAX) OUTPUT) AS DECLARE @Text_sysparm_suppress_pagination_header varchar(5) SET @Text_sysparm_suppress_pagination_header = CASE WHEN @Sysparm_suppress_pagination_header = 0 THEN 'false' ELSE 'true' ?END 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', 'attachment' EXEC SQLHTTP.net.QueryStringBuilder @QueryString OUTPUT, @Profile, 'sysparm_query', @Sysparm_query, 'sysparm_limit', @Sysparm_limit, 'sysparm_offset', @Sysparm_offset, 'sysparm_read_replica_category', @Sysparm_read_replica_category, 'sysparm_suppress_pagination_header', @Text_sysparm_suppress_pagination_header SET @URL = @URL + @QueryString 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 |
DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) EXEC usp_ServiceNow_Attachments_Fetch @Profile = 'My ServiceNow', @Sysparm_query = 'ORDERBYfile_name^ORDERBYDESCtable_Name', @Sysparm_limit = 5, @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/result' -- SELECT T.C.value(N'sys_id[1]', N'nvarchar(MAX)') AS [sys_id] ,T.C.value(N'file_name[1]', N'nvarchar(MAX)') AS [file_name] ,T.C.value(N'size_bytes[1]', N'nvarchar(MAX)') AS [size_bytes] ,T.C.value(N'download_link[1]', N'nvarchar(MAX)') AS [download_link] FROM @X.nodes(N'/response/result') T(C) END |
1 2 3 4 5 6 7 8 9 |
sys_id file_name size_bytes download_link --------------- ---------------------------------------- ----------- ------------------------ 186ac8df4f7... 1.1_4_workspace_overview_homepage_H.png 81345 https://dev32049.servi... d02cc4134fb... 1.2_3_change-homepage-layout_H.png 96632 https://dev32049.servi... e45dc1534ff... 1.2_4_create-a-new-homepage.png 23592 https://dev32049.servi... f5d469d74ff... 1.3_4_remove-a-favorite.png 190660 https://dev32049.servi... 10496b42670... 10496b426702120030ab159672415a2b 255 https://dev32049.servi... |
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.