Forums

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

Incremental number field using script runner for jira

Pooja
Contributor
October 15, 2018

Hi All,

In my Jira instance, I have one number custom field. the thing is it has to generate the set of number automatically when the ticket is created, like Jira issue ticket number

 

Thanks in advance

2 answers

1 vote
Tarun Sapra
Community Champion
October 15, 2018

Hello @Pooja

You can use logic in post-funciton of create transition to fetch the issue Key and add a random number logic and create a new number for the custom field.

There are plenty of examples of generating random numbers available in java/groovy.

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.
October 15, 2018

Yes, you can do this, but you are going to run into two problems:

1.  It is possible for two issues to get the same number if they are created at a similar times

2. It's going to be useless.  There are no advantages to sticking yet another identifier on a Jira issue when the issue key has more use and is what your users will use.

Pooja
Contributor
October 15, 2018

Hi @Nic Brough -Adaptavist-

Thank you for the suggestion.

I am okay with the problems. Can you suggest me how to create a field using script runner?

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.
October 16, 2018

I would create the field manually, adding a simple numeric field to all issues.  Do not place it on any edit or create screens.

You will then need to create a post-function or listener with a script (a listener is probably easier, as you won't need to add it to every workflow like you would with a post-function).  

The listener should listen for create issue events, run a search for "new field is not empty", get the highest number from that and add to it before populating the field.

Pooja
Contributor
October 16, 2018

@Nic Brough -Adaptavist-

1. Adding a simple numeric field to all issues- could you still more elaborate on this part.

2. You will then need to create a post-function or listener with a script- In my case, I just want this feature for the single project so I thought of using post function and suggest me with the script.

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.
October 16, 2018

I'm not sure how to elaborate on "add a new field" - log in as an admin, and add a field, like all the other custom fields.

I don't have time to write scripts for other people, especially not ones that don't have any use and can go wrong.

Suggest an answer

Log in or Sign up to answer