How to write a SQL query to update custom field data to jira “description” field?

Hi,

How to write a SQL query to update custom field data to jira “description” field?

The custom field name = Issue Description
Filed Type = Free Text Field unlimited text

How do I update from above mention custom field to jira “description” field for a "selected Project" by using with SQL query.?

Could you please provide the SQL script, so that I can use that query to update the data from custom field to description field.

Thanks
Ganga S

2 answers

1 accepted

Hi Ganga,

The following works on MySQL but i'm not sure if other databases understand that as well

update jiraissue,customfieldvalue
set jiraissue.description = customfieldvalue.textvalue 
where customfield = 12345 and jiraissue.id = customfieldvalue.issue and jiraissue.project = xxxxx;

12345 is the id of your unlimited text area custom field, xxxxx is the id of your project

Please always follow Nics hints for such operations

Hi Dieter,

Thanks for the SQL query. It is really useful.

I am using MS SQL 2008 R2, first I will try on our test environment and let you know the status.

Sure, I will follow the @Nic instructions before proceed and also I took the table backup using with

Select *into jiraschema.jiraissue_bak fromjiraschema.jiraissue

It means, for a test, I am going to run the update query on the backup table instead actual table

Ganga S

Hi Nic/Dieter.

Firstly: Thanks for the help....

It works. I used outer join query to update data from custom field to jira issue description field on a SQL 2008 R2 database. Outer join updates only matching records.

update jiraschema.jiraissue
set jiraschema.jiraissue.description = jiraschema.customfieldvalue.textvalue
from jiraschema.jiraissue left join jiraschema.customfieldvalue
on jiraschema.customfieldvalue.issue = jiraschema.jiraissue.id
where jiraschema.customfieldvalue.customfield = 12345
and jiraschema.jiraissue.project = xxxxx;

Ganga S

1 vote

It's not a simple script. To get the data out, you need to read "jiraissue where project = xxxxx" (xxxxx being the project you're interested in - read table "project" to find that), then for each jiraissue record found, read "customfieldvalue.text where issue = jiraissue.id and customfield = yyyyy" (where yyyyy = the custom field id for your free text field). Finally, to write the data, you update jiraissue.description with the value you've just read.

Please remember that when you do this, you absolutely MUST

  1. Take Jira offline
  2. Take a backup
  3. Restore it to prove it is a good backup
  4. Run the SQL
  5. Restart Jira
  6. Re-index it

Thanks Nic,

I am nerves with complex query, but I will try on my test machine….

Ganga S

Always a good idea to test first :-)

The SQL Dieter gives looks correct to me, with a couple of minor points:

  1. I think it will overwrite all the descriptions on all the issues with the value of the custom field, which may not be what you want.
  2. Also, I'm not sure how MS-SQL will react if the customfield is empty. When a field is empty, Jira doesn't have any record at all for the value of the field, so "customfieldvalue.textvalue" won't come back with anything.

Thanks for the second consideration....

#1. I wanted to overwrite all the issues description for a particular "Project". It means not for other project issues description.

#2. It is an interesting point.... I will try on test machine first..... and update the status.

Ganga S

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

614 views 3 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you