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,465,087
Community Members
 
Community Events
176
Community Groups

How to have custom field to have Incremental Number or Sequence Generation for tickets

Edited

Hi ,

 

I want to have a custom field that should generate number sequence starting from given value and iterate over next issue creation.

 

E.g Starting Value=4000

My first ticket in Project should have value 4001, TEST-2 as 4002, TEST-3 as 4003 and so on.

 

I tried to create using Scripted field in Scriptrunner but it is not working. Value are not stored in Scripted field, So i cant take value and add+1 for next ticket.

 

Could you help in generating sequence of numbers iterating over tickets using scriptrunner Behaviour or Scripted Field

 

import com.atlassian.jira.issue.Issue
import org.apache.commons.lang3.StringUtils;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

def key=issue.getKey()
log.error(key)

def cctype = customFieldManager.getCustomFieldObject('customfield_1500')
LazyLoadedOption cctype_value=(LazyLoadedOption)issue.getCustomFieldValue(cctype)

String value=cctype_value.getValue()
log.error("Value"+value)
def startID = customFieldManager.getCustomFieldObject('customfield_1503')
def startvalue=issue.getCustomFieldValue(startID)
log.error("startvalue"+startvalue)

log.error(cctype_value.getClass())
log.error("Value1:")


if (value=="Development"){
log.error("Value2:")
def ccnid = customFieldManager.getCustomFieldObject('customfield_12501')
//def ccnid_value=issue.getCustomFieldValue(ccnid)
log.error("ccnid"+ccnid)

return (8000).toString()






//String stringToConvert = String.valueOf(ccnid_value);
//Long convertedLong = Long.parseLong(stringToConvert);
// log.error(convertedLong)
// return (convertedLong+1l).toString();


}

2 answers

Hi @Tamil @Florian PEREZ 

I have one jira version ...i want  increase version number only how it's possible do you have any idea about on this.

my version is like : 2022.11.0 - project v33.0.0

i want to increment in this manner : 2022.12.0 - project v33.1.0

                                                          2023.01.0 - project v33.2.0

 

Could you please help me out on this.

0 votes
Florian PEREZ Community Leader Mar 18, 2022

Hello , 

You can us the ID of the ticket to increment the counter but you'll need to set this value on every ticket to do like this. 

Since scripted field are not fixed (they're calculated when issue load) you can't even try to get the previous value and increment it. 

I'm afraid they're no real solution to do this without having the field on every issue. 

@Florian PEREZ  Is there any other way to define it using Scriptrunner Behaviour or other way?

 

How is the Jira Ticket(Jira Key) is incremented. Could we use same logic?

 

Thanks,

Tamil

Ticket number are stored in Database. You can't use the same logic since the scripted filed is calculated so let imagine what you can do and why it's not possible to think this way : 

You can set a hard value on DB (lets say 4000)

Every time you want to set the field on an issue you take the value and then you increment the value on the database ( for the future use  ) ( so you say to you issue you value is the one in the database [4000] and increase the value of the one in the database by one [4001])

If you look to your issue you will see that the value is 4001, because everytime you look at the issue the field is calculated. No value are stored.

So you can't use Scripted field for sure.

 

On the other side customfield store value, so maybe doing a script based on a customfield can do the trick.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events