You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
In my jira server instance we are using the Scriptrunner addon based on this want to create a scripted custom field (Test transition count) that counts the how many times transition used in a workflow and transition ID is (101). Please help me with the script that counts the how many times transition used. Please guide me how to achieve this script.
Thanks in advance,
Siva.
Got you point.
Possible solution:
You have to create a number field and then add a post-function in that particular transition to increment the particular custom field, with this each time you do a transition the field will get updated by 1.
Add below script in post-function:
Script:
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue;
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = customFieldManager.getCustomFieldObject(customField_id);
def currentValue = (Double)cf.getValue(issue) ?: 0
def newValue = currentValue+1;
cf.updateValue(null, issue, new ModifiedValue(currentValue,newValue), changeHolder);
Change customField_id to the field of the custom field.
Thank you very much for the help the script works perfectly but it shows the count only for recent updated issues is there any chance to count older issues as well. Once again thank you very much for the help
Thanks,
Siva
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, that's correct the method I have suggested works for recently transitioned tickets.
I only had this tried on my end, but there could be a way to create a scripted custom field to do that which currently I am unaware off.
I hope someone finds this post and suggest you !!
Regards,
Vishwas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also to add on this, since the field is created now as per logic it should count the transition as and when it is done like for ongoing tickets, maybe to search in history of issues for older issues you may have to write a script to check the history manager of the issue and then get the count in the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
May be you are right if we write a script to check the history manager of the issue and then get the count in the field. Is it any possibility for you to write a script for that and add in our existing script. Because i'm new to the scriptrunner so far i'm not perfect in scripts. Thanks for your help.
Thanks,
Siva.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Siva,
This is as far as I had tried.
May be some one can help you with the script for that :)
Regards,
Vishwas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Vishwas Your script is exactly what I'm trying to do, but for some reason its not working on my instance. I am only seeing one "customField_id" to replace - am i missing one? As far as I can tell the script is clean, but every time i run through the transition, the field has an empty value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @siva
I see that you are looking for a solution with ScriptRunner but let me recommend our ready-built solution that provides the best flexibility. Our team at OBSS built Time in Status app for this exact need. It is available for Jira Server, Cloud, and Data Center.
Time in Status mainly allows you to see how much time each issue spent on each status and on each assignee.
The app also has Status Count and Transition Count reports that show how many times each status and each transition was used. This is exactly what you want.
For all numeric report types, you can calculate averages and sums of those durations grouped by the issue fields you select. For example total in-progress time per customer (organization) or average resolution time per week, month, issuetype, request type, etc. The ability to group by parts of dates (year, month, week, day, hour) is particularly useful here since it allows you to compare different time periods or see the trend.
The app calculates its reports using already existing Jira issue histories so when you install the app, you don't need to add anything to your issue workflows and you can get reports on your past issues as well. It supports both Company Managed and Team Managed projects.
Time in Status reports can be accessed through its own reporting page, dashboard gadgets, and issue view screen tabs. All these options can provide both calculated data tables and charts.
And the app has a REST API so you can get the reports from Jira UI or via REST.
Using Time in Status you can:
https://marketplace.atlassian.com/apps/1211756/
EmreT
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply, here in my case the status had the 3 incoming transitions. So here the issue is it counts the all 3 transitions moves i just need only one transition move count. I hope you understand my concern please guide me any alternate ways thanks for the help.
Thanks,
Siva.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @siva
This should be already there by default in scriptrunner, check in "Browse" section search for
By logic one is moving to particular status when they transition an issue, hence you can use this.
So create a field with a name and choose the status, that should work !
Regards,
Vishwas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.