Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,218
Community Members
 
Community Events
185
Community Groups

How to create a numeric field with a value that increments value for every new issue created

Sid
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.
Oct 02, 2018

How to create a numeric field with a value that increments value for every new issue created in a project.

4 comments

Jobin Kuruvilla [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.
Oct 04, 2018

You will have to create a calculated, read-only, custom field. You can either write your own add-on or use plugins like script runner to create a scripted field.

Sid
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.
Oct 09, 2018

got the solution with the script runner plugin.

 

Create a text custom field (single line). In the example I added "Numbers" as field name. Then create a postfuntion with the script below. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchProvider

// get all the used numbers so far
def query = ComponentAccessor.getComponent(JqlQueryParser).parseQuery("project = JA AND 'Numbers' is not EMPTY ORDER BY 'Numbers' DESC")
def results = ComponentAccessor.getComponent(SearchProvider).search(query,ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),new PagerFilter(1))
int maxNumbers = 0
CustomField cField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Numbers")

// get the highest used number
for(Issue documentIssue: results.getIssues())

{ maxNumbers = documentIssue.getCustomFieldValue(cField) as Integer }
// set the new number
def newNumbers = ++maxNumbers as String
issue.setCustomFieldValue(cField, newNumbers)

 

Hope this helps to anyone looking similar type of fields 

Like Bill Tanner likes this

Works like a charm!  Thanks so much!

Hi @Sid 

 

I'm getting error in the last line " issue.setCustomFieldValue(cField, newNumbers) "

saying that - " The variable [issue] is undeclared "

 

Please help.

Sid
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.
Dec 15, 2019

@Sekhar Chandra 

Did you follow the same steps?

Sid
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.
Dec 15, 2019 • edited

updated script for jira 8

 

def results = ComponentAccessor.getComponent(SearchProvider).search(query,ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),new PagerFilter(1))
to
import com.atlassian.jira.bc.issue.search.SearchService

def search = ComponentAccessor.getComponent(SearchService).search(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), query, new PagerFilter(1))

and 

from
for(Issue documentIssue: results.getIssues())
{ maxNumbers = documentIssue.getCustomFieldValue(cField) as Integer }
to
for(Issue documentIssue: search.results)
{ maxNumbers = documentIssue.getCustomFieldValue(cField) as Integer }

 

Hello @Sid 

I want a script that will auto-increment the number field that is "Issue Ranking" having numbers from 1 to 100. So when I create an issue and manually number that issue say - 49(edit that issue ) then I need that the already existing 49 should become 50 and already existing 50 should become 51.. that is, it should automatically increment itself on the basis of what number I have selected in the recently created ticket.
similarly when I number the issue manually as 30 then already existing should be 31 and already existing 31 should be 32 and so on... 

Sid
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.
Oct 09, 2018 • edited

.

Hi im trying to use and i got an error:

the variable issue is undeclared

 

can someone please help

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchProvider

 

// get all the used Old_Test_ID so far
def query = ComponentAccessor.getComponent(JqlQueryParser).parseQuery("project = CEQB AND 'Old_Test_ID' is not EMPTY ORDER BY 'Old_Test_ID' DESC")
def results = ComponentAccessor.getComponent(SearchProvider).search(query,ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),new PagerFilter(1))
int maxOld_Test_ID = 0
CustomField cField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Old_Test_ID")

// get the highest used number
for(Issue documentIssue: results.getIssues())

{ maxOld_Test_ID = documentIssue.getCustomFieldValue(cField) as Integer }
// set the new number
def newOld_Test_ID = ++maxOld_Test_ID as String
issue.setCustomFieldValue(cField, newOld_Test_ID)

Hi Dan, 

I also got stuck at this point. The failure seems to be with the last line.

 

issue.setCustomFieldValue(cField, newOld_Test_ID)

 

Did you find a solution?

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events