how to ceate an auto increment custom field on jira

I want to create an custom field wher it will be auto increment Exemple :

when the statut is Reopen this custom field = custom field +1

3 answers

Hello Tasher.

This is an incoming feature that is almost ready to be released, is is named "Canned Scripted Fields" and as I said, it will be out shortly as an out of the box script. However, if you are in a hurry here is a custom script,  Steven Cheesley kindly helped customising the initial script so that it would work in a custom scripted field

Here is the code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.history.ChangeItemBean

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def status = "In Progress"

def count = 0
// ::.. Check the state changes that have occurred ..::
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.each { ChangeItemBean item ->
    // Do all the froms and then get the current state and add it to the count
    if (item.fromString in status) 
     count++
}

//::.. Check the current state ..::
if (issue.getStatus().name in status) 
 count++
return count ? count as Integer : null
    

Here is the custom field config, which is relatively simple:

Screen Shot 2017-06-08 at 10.08.32.png

And as you can see in these pictures, it works:

Screen Shot 2017-06-08 at 10.06.07.pngHope this helped, good luck!

DYelamos

It work :D

Thank you so much 

Hey Tasher, if it solved your issue, could you please kindly mark the answer as resolved?

Cheers!

 

can you help me for this code 

import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.util.JiraUtils

 def currentComponents = issue.getComponents()
 
def workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class )
workflowTransitionUtil.setIssue(issue)
workflowTransitionUtil.setUserkey(currentUser.name)

for (c in currentComponents) {
 if (c.getName() == "NEW URL") {
  workflowTransitionUtil.setAction(191)
 }
 else {
  workflowTransitionUtil.setAction(181)
 }
}
 
workflowTransitionUtil.validate()
workflowTransitionUtil.progress()

I want to verify the component choose and choose if issue will be open or closed or assigned 

can the script above be modified to have the counter do a +1 when a new issue of the same issue type is created please ? so as to act like a unique code for a particular issue type?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jun 14, 2018 in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

424 views 2 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you