Table Record - Update
Update a ServiceNow 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
CREATE PROCEDURE usp_ServiceNow_Table_Record_Update( @Profile nvarchar(100), @TableName varchar(MAX), @Sys_id varchar(50), @Sysparm_display_value varchar(5) = NULL, @Sysparm_fields varchar(MAX) = NULL, @Sysparm_view varchar(MAX) = NULL, @Sysparm_exclude_reference_link varchar(MAX) = NULL, @Sysparm_input_display_value bit = NULL, @Body varchar(MAX), @Response nvarchar(MAX) OUTPUT, @StatusCode int OUTPUT, @StatusDescription nvarchar(MAX) OUTPUT) AS DECLARE @Text_sysparm_input_display_value varchar(5) SET @Text_sysparm_input_display_value = CASE WHEN @Sysparm_input_display_value = 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', 'table', @TableName, @Sys_id EXEC SQLHTTP.net.QueryStringBuilder @QueryString OUTPUT, @Profile, 'sysparm_display_value', @Sysparm_display_value, 'sysparm_fields', @Sysparm_fields, 'sysparm_view', @Sysparm_view, 'sysparm_exclude_reference_link', @Sysparm_exclude_reference_link, 'sysparm_input_display_value', @Text_sysparm_input_display_value 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 = 'PUT', @Body = @Body, @ContentType = 'application/json', @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 38 39 40 41 42 43 44 45 46 |
DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) DECLARE @Body varchar(MAX) SET @Body = '{ "assigned_to":"681b365ec0a80164000fb0b05854a0cd", "urgency":"1", "comments":"Elevating urgency, this is a blocking issue" }' EXEC usp_ServiceNow_Table_Record_Update @Profile = 'My ServiceNow', @TableName = 'incident', @Sys_id = '9e098c630f72030041ea06ace1050e1d', @sysparm_display_value = 'false', @sysparm_input_display_value = 1, @Body = @Body, @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'number[1]', N'nvarchar(MAX)') AS [number] ,T.C.value(N'category[1]', N'nvarchar(MAX)') AS [category] ,T.C.value(N'urgency[1]', N'nvarchar(MAX)') AS [urgency] ,T.C.value(N'assigned_to[1]/value[1]', N'nvarchar(MAX)') AS [assigned_to_value] FROM @X.nodes(N'/response/result') T(C) END |
1 2 3 4 5 |
sys_id number category urgency assigned_to_value -------------------------- ----------- ---------- --------- --------------------------------- 9e098c630f72030041ea0... INC0010004 inquiry 1 681b365ec0a80164000fb0b05854a0cd |
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.