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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Automation Ticket counter Field

Hello community,

 

i have one question. we have one data transfer for the purpose of another project and it is necessary to always transfer one unique number 50 000 plus one for each ticket. This is a global rule and that counter would go from 50,000 and plus one for each ticket where the issue type is this and that.

I tried the incement function but I don't have a reference to the previous ticket and it always counts at one.

 

If you can help me here I would be very grateful.

 

We can also look at this as some  counter that counters from number 50,000 up for each ticket created.

 

TY Jurica

 

2 answers

1 accepted

2 votes
Answer accepted

Using JMWE, there are two approaches:

  1. store the counter in a project entity property
  2. search for the issue with the greatest number, and increment it by one

I'm not sure I quite understood what you meant by "data transfer for the purpose of another project" though. So my example will be based on automatically setting a Number custom field upon issue creation.

Both approaches rely on adding a Set Field Value post-function on the Create transition of the project, to set a "counter" number field. The "Value type" must be "Groovy Expression" in both cases, only the Value Groovy script changes.

1. store the counter in a project entity property

def counter = issue.projectObject.getEntityProperty("my-counter")
if (!counter)
counter = 50000
else
counter++
issue.projectObject.setEntityProperty("my-counter", counter)
return counter

2. search for the issue with the greatest number, and increment it by one

def maxIssue = jqlSearch( """project = ${issue.projectObject.key} order by counter desc""" , 1 )
return maxIssue ? maxIssue.get("counter") + 1 : 50000

Solution number one works great, what it should do but in one project. We need it to work in all projects that have the same issue typ.

 

It would be good to have it on two issue typ's that do not share one workflow if possible?

 

Can you still help me David?

 

Best regards Jurica

Both solutions will work even across projects, with some changes.

But is the counter global or per issue type?

Like John Funk likes this

It is not global.

These are exclusively two issue types "Change request" and "3IT Change request". One has about 100 projects and the other about 50. Both two should use the same counter starting at 50,000 and each ticket in all 150 projects should then be counted for each Create one up.

 

They also use different workflows. So I have to probably make settings for the second typ in his own workflow?

 

Can the counter start immediately from 50,000, because it only starts  when I enter the value in the Field?

 

TY David

What I meant by a global counter is using the same counter for both issue types.

Since there should be only one counter, the first solution would be the same except that you need to pick one project (any project really) to hold the entity property. For example:

def project = ComponentAccessor.projectManager.getProjectByCurrentKey("TEST")
def counter = project.getEntityProperty("my-counter")
if (!counter)
counter = 50000
else
counter++
project.setEntityProperty("my-counter", counter)
return counter

As for the second solution, it's even simpler: 

def maxIssue = jqlSearch( "order by counter desc" , 1 )
return maxIssue ? maxIssue.get("counter") + 1 : 50000 

 which will look at all issues and return the one that has the highest "counter" value.

As to applying it to specific issue types:

- if each issue type has its own workflow, you just need to add the exact same post-function to the Create transition of both workflows

- if one (or both) workflow(s) is shared with other issue types that should not participate in this counter, then you'll need to add "conditional execution" to the Set Field Value post-function to only run the post-function for the right issue type.

Like Jurica Petricevic likes this

Perfectly. Exactly what I was looking for. Thank you very much.

1 vote

I'm not sure you can implement this with Jira Automation. You might need to use another app, such as our own JMWE app, or ScriptRunner.

Hi David, can u tell me how? I have JMWE also. Any tipps?

Like John Funk likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

107 views 1 8
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you