Update readonly fields (e.g. ClosedBy, ResolvedBy)
Some fields (e.g. ResolvedBy, ClosedBy) are read-only under normal rules. To update them you must set BypassRules='true' in the WITH clause. Use this only when you need to set system or audit fields; suppress notifications or validate-only options are also available in WITH for testing or reducing email noise.
Standard SQL query example
This is the base query accepted by the connector. To execute it in SQL Server, you have to pass it to the Data Gateway via a Linked Server. See how to accomplish this using the examples below.
UPDATE WorkItems
SET [Title] = 'Update-QA Task <<FUN_NOW>>'
, [Description] = 'Updated desc <<FUN_NOW>>'
, [WorkItemType]='Bug' -- Task
, [State] = 'Resolved'
, [Tags] = 'odata; api'
, [ResolvedBy] = 'some.one@mycompany.com' --(Must set ByPassRules='true' Param to set this readonly field)
WHERE [Id] = 9626
WITH(
BypassRules='true' --Useful to Update ReadOnly Fields like ResolvedBy, ClosedBy
-- ,SuppressNotifications='true' --Avoids email notifications on change
-- ,ValidateOnly='true' --Dont perform actual update - just validate
)
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_AZURE_DEVOPS_IN_GATEWAY], 'UPDATE WorkItems
SET [Title] = ''Update-QA Task <<FUN_NOW>>''
, [Description] = ''Updated desc <<FUN_NOW>>''
, [WorkItemType]=''Bug'' -- Task
, [State] = ''Resolved''
, [Tags] = ''odata; api''
, [ResolvedBy] = ''some.one@mycompany.com'' --(Must set ByPassRules=''true'' Param to set this readonly field)
WHERE [Id] = 9626
WITH(
BypassRules=''true'' --Useful to Update ReadOnly Fields like ResolvedBy, ClosedBy
-- ,SuppressNotifications=''true'' --Avoids email notifications on change
-- ,ValidateOnly=''true'' --Dont perform actual update - just validate
)')
Using EXEC in SQL Server (handling larger SQL text)
The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements.
This often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).
Fortunately, starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY] syntax.
DECLARE @MyQuery NVARCHAR(MAX) = 'UPDATE WorkItems
SET [Title] = ''Update-QA Task <<FUN_NOW>>''
, [Description] = ''Updated desc <<FUN_NOW>>''
, [WorkItemType]=''Bug'' -- Task
, [State] = ''Resolved''
, [Tags] = ''odata; api''
, [ResolvedBy] = ''some.one@mycompany.com'' --(Must set ByPassRules=''true'' Param to set this readonly field)
WHERE [Id] = 9626
WITH(
BypassRules=''true'' --Useful to Update ReadOnly Fields like ResolvedBy, ClosedBy
-- ,SuppressNotifications=''true'' --Avoids email notifications on change
-- ,ValidateOnly=''true'' --Dont perform actual update - just validate
)'
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY]