How to create a numeric field with a value that increments value for every new issue created in a project.
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.
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.ComponentAccessorimport com.atlassian.jira.jql.parser.JqlQueryParserimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.search.SearchProvider
// get all the used numbers so fardef 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 = 0CustomField cField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Numbers")
// get the highest used numberfor(Issue documentIssue: results.getIssues())
{ maxNumbers = documentIssue.getCustomFieldValue(cField) as Integer }// set the new numberdef newNumbers = ++maxNumbers as Stringissue.setCustomFieldValue(cField, newNumbers)
Hope this helps to anyone looking similar type of fields
.
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.
@Sekhar Chandra
Did you follow the same steps?
Hi im trying to use and i got an error:
the variable issue is undeclared
can someone please help
// get all the used Old_Test_ID so fardef 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 = 0CustomField cField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Old_Test_ID")
{ maxOld_Test_ID = documentIssue.getCustomFieldValue(cField) as Integer }// set the new numberdef newOld_Test_ID = ++maxOld_Test_ID as Stringissue.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?
It looks like you're new here. Sign in or register to get started.