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

Wanted script for (Scriptrunner)Transition count in workflow

siva January 19, 2022

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.

4 answers

1 accepted

1 vote
Answer accepted
Vishwas
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.
January 20, 2022

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.

siva January 20, 2022

@Vishwas 

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

Vishwas
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.
January 20, 2022

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

Vishwas
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.
January 20, 2022

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.

siva January 20, 2022

@Vishwas 

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.

Vishwas
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.
January 21, 2022

Hey Siva,

This is as far as I had tried.

May be some one can help you with the script for that :)

Regards,

Vishwas

Cailin Che April 13, 2023

@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

0 votes
Emre Toptancı _OBSS_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 19, 2022

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. 

tisCloud_StatusDuration_LeadTime_with Estimates.png  tisCloud_AssigneeDuration.png     

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.

TransitionCount.png  StatusCount.png

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.

tisCloud_StatusDuration_LeadTime_Average_TimeGrouped.png

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.

Gadget_AverageStatusDurationByComponent.png  tisCloud_StatusDuration_LeadTime_Chart.png

Using Time in Status you can:

  • See how much time each issue spent on each status, assignee, user group and also see dates of status transitions.
  • Calculate averages and sums of those durations grouped by issue fields you select. (For example, see average InProgress time per project and per issue type.)
  • Export your data as XLS, XLSX, or CSV.
  • Access data via REST API. (for integrations)
  • Visualize data with various chart types.
  • See Time in Status reports on Jira Dashboard gadgets

https://marketplace.atlassian.com/apps/1211756/

EmreT

0 votes
siva January 19, 2022

@Vishwas 

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.

0 votes
Vishwas
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.
January 19, 2022

Hey @siva 

This should be already there by default in scriptrunner, check in "Browse" section search for

No. of Times In Status

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events