Forums

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

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

Tamil March 18, 2022

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

0 votes
prakash November 28, 2022

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
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.
March 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. 

Tamil March 18, 2022

@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

Florian PEREZ
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.
March 18, 2022

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