Create work item with many fields
Creates a work item with a full set of common fields: type, title, description, tags, area and iteration path, assignee, priority, triage, task type, dates, estimates, story points, and more. Use this as a template when you need to set many fields at once. Omit or comment out columns you do not need; add custom fields with the Custom prefix as in the connector docs.
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.
INSERT INTO WorkItems (
[WorkItemType]
, [Title]
, [Description]
, [Tags]
, [AreaPath]
, [IterationPath]
, [AssignedTo]
, [Priority]
, [Triage]
--, [StackRank]
, [Blocked]
, [TaskType]
, [RequiresReview]
, [RequiresTest]
, [IntegrationBuild]
, [FoundIn]
, [OriginalEstimate]
, [RemainingWork]
, [CompletedWork]
, [Size]
, [Effort]
, [TargetDate]
, [StartDate]
, [FinishDate]
, [DueDate]
, [StoryPoints]
--, [Discipline]
, [SystemInfo]
, [Steps]
, [ReproSteps]
--, [CustomFieldText] --custom field prefix with CustomYOUR_FIELD_NAME_WITHOUT_SPACE_OR_DASH_OR_DOT
--, [CustomFieldDate]
--, [CustomFieldNumber]
--, [CustomFieldDecimal]
--, [CustomFieldPickListString]
--, [CustomFieldPickListNum]
)
VALUES (
'Bug' -- Task, User Story -- WorkItemType
, 'My Task Title - Created on <<FUN_NOW>>' --Title
, 'Some Description - Created on <<FUN_NOW>>' --Description
, 'odata; api' --Tags
, 'ProductTesting\SSISPowerPack' --AreaPath
, 'ProductTesting\2021.6' --IterationPath
, 'build@mycompany.com' --AssignedTo
, 1 --Priority
, 'Pending' --Triage
--, ??? --[StackRank]
, 'No' --Blocked
, 'Planned' --TaskType
, 'No' --RequiresReview
, 'No' --RequiresTest
, '101.1.2.3' --IntegrationBuild
, '100.1.2.3' --FoundIn
, 9999.111 --OriginalEstimate
, 9999.222 --RemainingWork
, 9999.333 --CompletedWork
, 9999.444 --Size
, 9999.555 --Effort
, '2021-01-31' --TargetDate
, '2022-01-31' --StartDate
, '2023-01-31' --FinishDate
, '2024-01-31' --DueDate
, 100.5 --StoryPoints
--, 'Some Discipline' --Discipline
, 'Windows 10' --SystemInfo
, 'Here are steps' --Steps
, 'Here are steps to reproduce' --ReproSteps
--, 'abcd' --CustomFieldText
--, '2021-01-31' --CustomFieldDate
--, 9999 --CustomFieldNumber
--, 9999.123 --CustomFieldDecimal
--, 'BBB' --CustomFieldPickListString
--, '2' --CustomFieldPickListNum
)
WITH(
Project='ProductTesting'
-- ,BypassRules='true' --Useful to set ReadOnly Fields like ResolvedBy, ClosedBy
-- ,SuppressNotifications='true' --Avoids email notifications on change
-- ,ValidateOnly='true' --Dont perform actual insert - just validate
)
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_AZURE_DEVOPS_IN_GATEWAY], 'INSERT INTO WorkItems (
[WorkItemType]
, [Title]
, [Description]
, [Tags]
, [AreaPath]
, [IterationPath]
, [AssignedTo]
, [Priority]
, [Triage]
--, [StackRank]
, [Blocked]
, [TaskType]
, [RequiresReview]
, [RequiresTest]
, [IntegrationBuild]
, [FoundIn]
, [OriginalEstimate]
, [RemainingWork]
, [CompletedWork]
, [Size]
, [Effort]
, [TargetDate]
, [StartDate]
, [FinishDate]
, [DueDate]
, [StoryPoints]
--, [Discipline]
, [SystemInfo]
, [Steps]
, [ReproSteps]
--, [CustomFieldText] --custom field prefix with CustomYOUR_FIELD_NAME_WITHOUT_SPACE_OR_DASH_OR_DOT
--, [CustomFieldDate]
--, [CustomFieldNumber]
--, [CustomFieldDecimal]
--, [CustomFieldPickListString]
--, [CustomFieldPickListNum]
)
VALUES (
''Bug'' -- Task, User Story -- WorkItemType
, ''My Task Title - Created on <<FUN_NOW>>'' --Title
, ''Some Description - Created on <<FUN_NOW>>'' --Description
, ''odata; api'' --Tags
, ''ProductTesting\SSISPowerPack'' --AreaPath
, ''ProductTesting\2021.6'' --IterationPath
, ''build@mycompany.com'' --AssignedTo
, 1 --Priority
, ''Pending'' --Triage
--, ??? --[StackRank]
, ''No'' --Blocked
, ''Planned'' --TaskType
, ''No'' --RequiresReview
, ''No'' --RequiresTest
, ''101.1.2.3'' --IntegrationBuild
, ''100.1.2.3'' --FoundIn
, 9999.111 --OriginalEstimate
, 9999.222 --RemainingWork
, 9999.333 --CompletedWork
, 9999.444 --Size
, 9999.555 --Effort
, ''2021-01-31'' --TargetDate
, ''2022-01-31'' --StartDate
, ''2023-01-31'' --FinishDate
, ''2024-01-31'' --DueDate
, 100.5 --StoryPoints
--, ''Some Discipline'' --Discipline
, ''Windows 10'' --SystemInfo
, ''Here are steps'' --Steps
, ''Here are steps to reproduce'' --ReproSteps
--, ''abcd'' --CustomFieldText
--, ''2021-01-31'' --CustomFieldDate
--, 9999 --CustomFieldNumber
--, 9999.123 --CustomFieldDecimal
--, ''BBB'' --CustomFieldPickListString
--, ''2'' --CustomFieldPickListNum
)
WITH(
Project=''ProductTesting''
-- ,BypassRules=''true'' --Useful to set ReadOnly Fields like ResolvedBy, ClosedBy
-- ,SuppressNotifications=''true'' --Avoids email notifications on change
-- ,ValidateOnly=''true'' --Dont perform actual insert - 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) = 'INSERT INTO WorkItems (
[WorkItemType]
, [Title]
, [Description]
, [Tags]
, [AreaPath]
, [IterationPath]
, [AssignedTo]
, [Priority]
, [Triage]
--, [StackRank]
, [Blocked]
, [TaskType]
, [RequiresReview]
, [RequiresTest]
, [IntegrationBuild]
, [FoundIn]
, [OriginalEstimate]
, [RemainingWork]
, [CompletedWork]
, [Size]
, [Effort]
, [TargetDate]
, [StartDate]
, [FinishDate]
, [DueDate]
, [StoryPoints]
--, [Discipline]
, [SystemInfo]
, [Steps]
, [ReproSteps]
--, [CustomFieldText] --custom field prefix with CustomYOUR_FIELD_NAME_WITHOUT_SPACE_OR_DASH_OR_DOT
--, [CustomFieldDate]
--, [CustomFieldNumber]
--, [CustomFieldDecimal]
--, [CustomFieldPickListString]
--, [CustomFieldPickListNum]
)
VALUES (
''Bug'' -- Task, User Story -- WorkItemType
, ''My Task Title - Created on <<FUN_NOW>>'' --Title
, ''Some Description - Created on <<FUN_NOW>>'' --Description
, ''odata; api'' --Tags
, ''ProductTesting\SSISPowerPack'' --AreaPath
, ''ProductTesting\2021.6'' --IterationPath
, ''build@mycompany.com'' --AssignedTo
, 1 --Priority
, ''Pending'' --Triage
--, ??? --[StackRank]
, ''No'' --Blocked
, ''Planned'' --TaskType
, ''No'' --RequiresReview
, ''No'' --RequiresTest
, ''101.1.2.3'' --IntegrationBuild
, ''100.1.2.3'' --FoundIn
, 9999.111 --OriginalEstimate
, 9999.222 --RemainingWork
, 9999.333 --CompletedWork
, 9999.444 --Size
, 9999.555 --Effort
, ''2021-01-31'' --TargetDate
, ''2022-01-31'' --StartDate
, ''2023-01-31'' --FinishDate
, ''2024-01-31'' --DueDate
, 100.5 --StoryPoints
--, ''Some Discipline'' --Discipline
, ''Windows 10'' --SystemInfo
, ''Here are steps'' --Steps
, ''Here are steps to reproduce'' --ReproSteps
--, ''abcd'' --CustomFieldText
--, ''2021-01-31'' --CustomFieldDate
--, 9999 --CustomFieldNumber
--, 9999.123 --CustomFieldDecimal
--, ''BBB'' --CustomFieldPickListString
--, ''2'' --CustomFieldPickListNum
)
WITH(
Project=''ProductTesting''
-- ,BypassRules=''true'' --Useful to set ReadOnly Fields like ResolvedBy, ClosedBy
-- ,SuppressNotifications=''true'' --Avoids email notifications on change
-- ,ValidateOnly=''true'' --Dont perform actual insert - just validate
)'
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY]