Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Setting IssueKey (Number) while creating issues?

Klaus Foerschl
Contributor
July 1, 2022

Hello.

We have built a "synchronization" tool, based on the Jira REST API, which allows us to create or update issues based on "exports" from any other tool.

Now we are thinking about migrating a Jira project (+ Confluence & Bitbucket with references to Jira) from one server to another.

For that reason, the issue-keys (explicitly the number; e.g. PROJ1-12345, must be kept, in order to being able to keep the references working).

But, it seems, the REST API does not support setting the key during create.
We already tried in the JSON payload a "key": "PROJ1-12345", beside of the "fields" section. It seems to be ignored anyway.

Is there a possibility to set the issue key, during create with REST API?

Another thing we tried, is with the Java API.
We manipulated a MutableIssue Item with setNumber() and setProjectObject() and stored and reindexed it with the appropriate functions.
But also this did not work on already existing issues.
Might it be the case, that those setters are only good while creating issues, but not for "editing"?

 

Now i also tried to create an issue from scratch by Java API.
My code looks like (so, i'm more or less copying over attributes from an existing issues).
But, i do set the number actively.

long nr=999
def origIssue = issueItem.getIssueObjectByKey("TSTX1-1")
def newIssue = ComponentAccessor.getIssueFactory().getIssue()
newIssue.setProjectObject(origIssue.projectObject)
newIssue.setNumber(nr)
newIssue.setIssueType(origIssue.issueType)
newIssue.setSummary(origIssue.summary)
newIssue.setDescription(origIssue.description)
def created = ComponentAccessor.getIssueManager().createIssueObject(currentUser, newIssue)

 

After having the created object saved to the DB, i unfortunately has the next free number instead of the give 999.
I'm clueless what this methods should do and how to actively set the number as required.

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 1, 2022

No, you can not set the issue sequence in the REST API, and you should not have done it with your code either. Unless you've updated all the other things you need to, you have probably broken your Jira.

Jira determines the next free number in the project.  If you need to keep a note of the issue id in the old system, import it into a custom field.

Klaus Foerschl
Contributor
July 4, 2022

OK. Good no know. Thanks.
But, allow me the following question, then.

What is the purpose of the setNumber() method?

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/MutableIssue.html#setNumber-java.lang.Long-

The custom field, unfortunately, does not solf the problem, that references from e.g. Bitbucket & Confluence, after a migration won't work anymore, since the key changed.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2022

It's there for letting the issue create code put a value into the issue.

You don't really have any other option than putting the value into a custom field if you want to keep a record of it.  You can not set an issue key in Jira, only Jira can.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.6
TAGS
AUG Leaders

Atlassian Community Events