Update custom multi-select, user, or team fields (raw JSON)
Shows how to update custom fields that hold multiple values or complex types (e.g. multi-select, user, team) using raw JSON. Supply a JSON array or object as required by the field type; to clear, set the column to null. Use SELECT * FROM Fields to find your custom field IDs.
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 Issues
SET customfield_10048='[{"value":"AAA"}, {"value":"CCC"}]' --supply raw json
WITH (IssueIdOrKey='10020')
--OR--
UPDATE Issues
SET customfield_10048 =null --set to null
WITH (IssueIdOrKey='10020')
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_JIRA_IN_GATEWAY], 'UPDATE Issues
SET customfield_10048=''[{"value":"AAA"}, {"value":"CCC"}]'' --supply raw json
WITH (IssueIdOrKey=''10020'')
--OR--
UPDATE Issues
SET customfield_10048 =null --set to null
WITH (IssueIdOrKey=''10020'')')
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_JIRA_IN_GATEWAY] syntax.
DECLARE @MyQuery NVARCHAR(MAX) = 'UPDATE Issues
SET customfield_10048=''[{"value":"AAA"}, {"value":"CCC"}]'' --supply raw json
WITH (IssueIdOrKey=''10020'')
--OR--
UPDATE Issues
SET customfield_10048 =null --set to null
WITH (IssueIdOrKey=''10020'')'
EXEC (@MyQuery) AT [LS_TO_JIRA_IN_GATEWAY]