Count Issue Types

Marcelo Ignacio Cid Abud April 19, 2023

Hi Community,

I try to count issue type story through an automation.

For example:

Actions:

1. When I create one issuetype = story the custome field (Correlative) is equal to 1

2. When I create other issuetype = task the custome field (Correlative) is equal to 1

3. When I create one issuetype = story the custome field (Correlative) is equal to 2

 

Because I created two story (Action 1 and 2)

2 answers

1 accepted

2 votes
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2023

Hi Marco,

I think I understand what you are trying to do here, I have put together an automation rule example, that I think might meet your criteria here.  Check it out:

Screenshot 2023-04-21 at 11.25.44 AM.png

In my example, I have a numeric field called NewNum.  My trigger is upon issue creation.  This is also a project specific automation rule (not a global or multi-project rule).  By doing a Lookup issues and then choosing the JQL of

NewNum is not EMPTY ORDER BY key desc

This way automation will do a JQL query to return the issues in this project that have some value for that custom field, and order them from most recently created to oldest, since Jira increments the issue keys when new issues are created.

From there I do a re-fetch data, just to make sure we give the lookup enough time to gather that info, before you can then do an edit issue action to set the NewNum on the newly create issue. I used the smart value of

{{lookupIssues.get(0).NewNum.plus(1)}}

To look at the first entry of the JQL lookup (0 being the first indexed issue), you can use the get(0) along with the custom field name, and then we can use a simple math operation of plus(1) to increment the other issue's value and store it to that field.

 

This method should allow you to have potentially deleted issues in the project and still new issues will lookup the most recently created issue and use that issues field value when determining the next number to use.

Does this help?

 

Andy

Marcelo Ignacio Cid Abud April 24, 2023

:OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

I think it's exactly what I was looking for. I'll give it a week's trial and I'll confirm.

Thanks @Andy Heinzer 

Marcelo Ignacio Cid Abud April 25, 2023

Hi @Andy Heinzer - @Trudy Claspill 

Now I have the following problem

Captura.JPG

How can I give the following value to the tickets that did not take the correlative value and that have already been created?
MAR1-632 -> Correlative = 2
MAR1-633-> Correlative = 3

and the next keys...

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 26, 2023

Those issue were created months ago, so the automation trigger of when issue is created won't be able to change those now.  In that case, there are a couple of different ways to go about it.

One approach would be to create a new automation rule.  You could copy the existing rule, but just change trigger from "Issue Creation" to some other trigger, such as "Edit issue" in which case the next time someone edits the issue it can update that field.  If you choose this route, you will want to add a condition check in the automation rule so that before making a change to the issue, check to see if the correlative field is empty.  Without that condition check, each edit to the issues would push that custom field value ever higher.

  

Marcelo Ignacio Cid Abud April 26, 2023

Hi @Andy Heinzer 

Is there a way to change MAR1-632 -> Correlative = 2 MAR 1-633-> Correlative = 3 massively?
I mean change the trigger (not when editing but something like calendar or something like that that can run immediately)

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 27, 2023

Hi @Marcelo Ignacio Cid Abud 

You can create a new rule to manage existing issues and update them with new values for this number field. 

Screenshot 2023-04-27 at 12.36.35 PM.png

Note that I changed the trigger to happen on Issue updated.  Also there is a conditional to check that this field is currently empty.  Once those two are there I adjusted the JQL query to lookup the highest number and increment that value by one.  The JQL for that in my example was:

NewNum is not EMPTY order by NewNum desc

This way, any user that edits/updates these existing issues will trigger automation to assign a value to those issues based on the issue with the highest value at the time of that edit.  Provided that the issues do not have a value for that field yet.

I hope that helps.

Andy

Marcelo Ignacio Cid Abud May 5, 2023

Hello @Andy Heinzer 

Sorry for the delay in my response but what you indicate does not work for me, I will try to explain myself better.

Tickets 632 and 633 are finished tickets so they will not be edited again. I am looking for an automation (for example, the calendar ones that can be run to confirm that everything is working) that allows me to update these tickets that are in Done and that will no longer be updated.

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 5, 2023

Thanks for the update.  Sorry that this solution doesn't meet the need here.  However trying to use a scheduled trigger that can search JQL isn't really an ideal approach here. 

That is because the actions taken in such an automation rule will have to apply to all the JQL search results equally.  Since we want to apply a different value (an increment) to each of the issues that are missing a value in this field, a scheduled automation rule really aren't well suited to see the correlated number and apply a correctly incremented value to all those issues in a single action.  Instead you would likely end up with issues having duplicate values for that correlation field.

That said, the previously suggested approach to set for a single issue at a time is going to be more accurate in seeing what the previous correlation value was and then using that value in the next issue to set.  Having two rules to this, one for issue creation, and another for managing the existing issues I believe is more feasible. 

You are not required to use the 'Issue edited' as a trigger though in that second rule.  You could just use something like the Manual trigger instead. However for a manual trigger, you would then still need to go to that issue, and select that automation to run on that issue in order for automation to be able to set the value.

Marcelo Ignacio Cid Abud May 8, 2023

Thanks for the help <3 @Andy Heinzer 

0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 19, 2023

Hello @Marcelo Ignacio Cid Abud 

What problem are you trying to solve by keeping track of how many issues of each type exist?

How do you need to use that information?

Marcelo Ignacio Cid Abud April 20, 2023

Hi @Trudy Claspill 

 

Because en Jira Service Management the corralative number of tickets has a problem.

I read in other foro that problem is in Jira (company) not the work space. For that I need one automation that coun the issuetype create.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 20, 2023

Hello Marcelo,

I don't think I understand your use case. In which issue do you want to record this information? Can you walk through the details of an example scenario? Providing screen images to illustrate your example would also be helpful.

If English is not your native language also feel free to use your native language and I will use a translator. Sometimes there is a misunderstanding due to language differences.

Marcelo Ignacio Cid Abud April 20, 2023

I tell you @Trudy Claspill ,

I have a custom field called Correlative, this field is a numeric field.

What I want to achieve is that each time a ticket is created, this field increases, that is, when I create a ticket it takes the value of 1, when I create another ticket it takes the value 2, when I create another ticket the value 3, and so on. successively

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 20, 2023

Do you want to count issues in a specific project? Or all issues created in all projects?

It sounds like you want to record the count of issues in every issue.

1. Create one story (ABC-1)
In ABC-1 set field Correlative to 1
2. Create another story (ABC-2)
In ABC-1 set field Correlative to 2
In ABC-2 set field Correlative to 2

3. Create a Task (ABC-3)
In ABC-3 set field Correlative to 1
4. Create another Task (ABC-4)
In ABC-4 set field Correlative to 2
In ABC-3 set field Correlative to 2

5. Create another Story (ABC-5)
In ABC-1 set field Correlative to 3
In ABC-2 set field Correlative to 3
In ABC-5 set field Correlative to 3

If that is not a valid representation of what you want to do, please provide a detailed example such as I have tried to do.

Is there some relationship between the issues besides having the same issue type? Is this per project or across all projects? Is it for all issue types? Or are you trying to count linked issues for each issue?

Marcelo Ignacio Cid Abud April 20, 2023

Thanks for the answer @Trudy Claspill 

but no :C.

1. Create one story (ABC-1)
In ABC-1 set field Correlative to 1

2. Create another story (ABC-2)
In ABC-1 set field Correlative to 1
In ABC-2 set field Correlative to 2

3. Create a Task (ABC-3)
In ABC-3 set field Correlative to 3

4. Create another Task (ABC-4)
In ABC-4 set field Correlative to 4
In ABC-3 set field Correlative to 3

5. Create another Story (ABC-5)
In ABC-1 set field Correlative to 1
In ABC-2 set field Correlative to 2
In ABC-5 set field Correlative to 5

 

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 20, 2023

I see. Thank you for that clarification.

The number portion of the issue ID (ABC-5) already provides that information.

Is there a reason you need that information stored in the issue separately?

If you really do need that, then you could set the field through an Automation Rule using this structure:

TRIGGER: When issue created
ACTION: Lookup Issues Action
JQL: project={{issue.project}}
ACTION: Edit issue
Field to edit: Correlative
Value: {{lookupIssues.size}}

The Lookup Issues action looks up all the issue in the same project as the one created. If you only want to count Tasks and Stories (i.e not Epics and Sub-tasks) refine the JQL accordingly.

The smart value {{lookupIssues.size}} is the number of issues found by the last Lookup Issues action.

Note that the Lookup Issues action has a limit of retrieving 100 issues. Are you expecting to have more than 100 issues in the project at some point?

Marcelo Ignacio Cid Abud April 20, 2023

Yes, I expect to have more than 100 problems, I would even say more than 1000.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 20, 2023

Then use this smart value to get the numeric portion of the issue key and set that into your Correlative field.

{{issue.key.substringAfterLast("-")}}

Marcelo Ignacio Cid Abud April 21, 2023

Hi @Trudy Claspill 

Good Moorning (in my country)

It´s work but I need this for the problem in service mangement.

https://jira.atlassian.com/browse/JRACLOUD-59371

https://jira.atlassian.com/browse/JRACLOUD-77334

For that I need generate a new "Correlative"

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2023

If you need to accommodate the situation where the numeric part of the issue key has not incremented sequentially, the only other option I can think of is that you would need to use the REST API to get the issue count.

The API call is explained here:

https://confluence.atlassian.com/jirakb/how-to-get-issue-count-for-each-project-along-with-the-last-update-time-1108684309.html

You would access the API using the Web Request action.

https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Send-web-request

There is an article on using the Web Request action here:

https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828

I have not worked with that specific action before. If you have questions about it I recommend that you start a new Question thread about that specifically so that other community members with knowledge will see that as a new topic and offer their guidance. They would not see the question about it if they were only buried in this existing Question. If you decide to try that action and start a new Question about it, put in that Question a link to this post to provide background information without having to re-enter everything we've discussed here.

Marcelo Ignacio Cid Abud April 21, 2023

@Trudy Claspill 

I understand but

Exist the possibility that I have the ultime issue created ?

For example:

Today I am going to create a ticket (ABC-3234) and I want to give a value to the correlative field but I want that value to be greater than the last ticket I create (ABC-3233) which has a value of 5, that is, when I create the ticket ABC-3234 the value that the correlative field must have is 6.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2023

I don't think I understand your requirement.

I thought the requirement was to set the Correlative field to the current total number of issues in the project including the issue that is being created.

Now it sounds like you want to set the field to be one more than the highest number used in that field in all the project issues.

Please try again to explain what information you want to use to determine the value to set for the Correlative field in the newly created issue.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2023

Hello @Marcelo Ignacio Cid Abud 

I think there may be some confusion because of differences in our native languages.

Can you please try posting in your native language, so that we can user translators to see if we understand more clearly?

Also, can you please try to explain the problem you are trying to solve rather than the change you are trying to implement? Why are you trying to record this number in each newly created issue? How will the data be used? If we understand the actual problem you are trying to solve we may be able to give you better advice.

Suggest an answer

Log in or Sign up to answer