Hi all! i am trying to run the code from the link
https://library.adaptavist.com/entity/count-the-time-an-issue-was-in-a-particular-status
But I am getting time "0"
Hi @Alex
I've tested the code in my environment and do not seem to be encountering any issues. I can get the expected result, as shown in the image below:-
I've used the same code to test, with a minor modification to the Issue Type as shown below:-
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.history.ChangeItemBean// Status to be countedfinal statusName = 'In Progress'def changeHistoryManager = ComponentAccessor.changeHistoryManagerdef totalStatusTime = [0L]// Every status change is checkeddef changeItems = changeHistoryManager.getChangeItemsForField(issue, 'status')changeItems.reverse().each { ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.time// Subtract time if the "from" status is equal to the status to be checked and from and to statuses are different.// This allows to count the time the issue is in the state for the first timeif (item.fromString == statusName && item.fromString != item.toString) { totalStatusTime << -timeDiff}// Add time if the "to" status is equal to the status to be checkedif (item.toString == statusName) { totalStatusTime << timeDiff }}def total = totalStatusTime.sum() as Long// Every time (added or subtracted) is summed and divided by 1000 to get seconds(total / 1000) as long ?: 0L
Could you please provide a screenshot of the issue history as shown below:-
Thank you and Kind regards,
Ram
HI @Alex
It may help to put in some log statements to show the values being obtained during the process .
What is the history of your TEST-10 item with status TO DO?
@Tom Lister hi!
The field type template should be Duration but that isn't the issue.
If I dry run this in my head, Your loop should process two events. Each of which will match one of the given conditions. So the net effect is one pass will add -timeDiff and the other will add +timeDiff. So giving a zero result.
As I mentioned you would have to add log statements to see some confirming debug info. I don't think this logic will work for this test case if any.
I've tagged adaptavist so hopefully they will jump in. If I had a running server instance I would try to recreate it.
@Ram Kumar Aravindakshan _Adaptavist_ hi! Thank you ! it's worked!
@Ram Kumar Aravindakshan _Adaptavist_ hello , I improved my counter a little , but now unfortunately I can not understand why tasks are not searched through jql search . by the "Fail" flag. Please could you help me understand what could be wrong here. Thank you.
Are you setting the Counter Status field in your improved code?Could you share the improved code?
It looks like you're new here. Sign in or register to get started.