Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,369,314
Community Members
 
Community Events
168
Community Groups

Autofill field "time spent" when issue status is changed

I am trying to track how much time issue spends in status "in progress" and transitions to "Done" by automatically updating "time spent".

Idea is to have "time spent" start tracking as soon as issue will leave "To do" to "In Progress" and finishes tracking as soon as status changes to "Done" and automatically updates the field "time spent".

Keeping in mind that it syncs with before applied 5 days and 8 hours of working regime in Jira.

 

Is it possible ?

We are using jira standard cloud version and jira classical software project.

5 answers

1 accepted

0 votes
Answer accepted

Hi @Kirill Gutmann 

Doing something like this is quite easy when you use scripting (both on server or cloud). This information is stored in the change history on an issue which can be fetched both by Jira Java API as well as REST API.

In case you are on server and have ScriptRunner then this script will help you in getting the change history like when the status changed?

In case you are on cloud (which is my guess) then using either ScriptRunner for Jira on Cloud or the built in Automation you can call Jira REST API to fetch the change history. I would prefer using ScriptRunner as writing a groovy script is easier, a bit more readable and can handle complex cases. In both cases you need this end point.

JIRAURL/rest/api/3/issue/{{issue.key}}?expand=changelog

Let us say you want to do it using Automation rules, then when you call this end point. You will get a response JSON back in a smart value which you can access like this.

{{webhookResponse.body.changelog.histories}}

Now if you log this smart value you will get the json of the histories part of all the change histories. Now you can further iterate over those list of items in the change histories.

{{#webhookResponse.body.changelog.histories}}
ID: {{id}}
Created: {{created}}
{{#items}}{{fromString}} - {{toString}} {{/}}
{{/}} 

This will give you all the items in the change log like this.

ID: 18206
Created: 2021-01-02T17:11:59.730+0000
To Do - In Progress 

ID: 18152
Created: 2021-01-01T16:40:30.859+0000
To Do - In Review

Going back to your requirement, once you know how to fetch a change history, then you can perform some calculations on the dates for specific field changes.

The second part of your requirement was to log work. There is an action to do that or you can do that using REST API.

I hope this will help you, it is a bit complex but lot of fun :)

Ravi

..btw you can't auto fill a field but can log work using automation.

Thank you very much, this is very helpful!

Like Ravi Sagar _Sparxsys_ likes this

Hi @Kirill Gutmann 

Adding onto what @Nic Brough _Adaptavist_ suggests for trying this with automation, you may want to add a couple of custom fields to make this easier, and then increment time spent based on those.  For example...

  • Add custom fields for Last Status Category, Last Status Category Changed
  • Add a rule, triggered on issue create, which sets the custom fields.  Note that  {{issue.statuscategorychangedate}} is a text field so consider converting it with toDate.
  • Add a rule, triggered on issue transition, to check for any changes to Status Category (compared to Last Status Category).  When it changes, do the math needed to increment time spent.  And then update the custom fields again, as needed.

Best regards,

Bill

Hello @Kirill Gutmann 

As an alternative solution, you can try Time between statuses by SaaSJet, which is an Atlassian marketplace vendor.

image.jfif

This add-on tracks transition time between statuses (e.g. from "in progress" to "done"). It also helps to set such calculation conditions as first/last transition and to/from status. 

I hope, you find it helpful

Best regards, Mariana

0 votes
Bloompeak Support Marketplace Partner Jan 29, 2021

Hi @Kirill Gutmann ,

As an alternative, you can try Status Time app developed by our team. It provides reports on how much time spent in each status as well as status entry dates and status transition count. Report can be exported as CSV, so that you can use external tools like Microsoft Excel or Google Spreadsheet to process the exported data.

Once you enter your working calendar into the app, it takes your working schedule into account too. That is, "In Progress" time of an issue opened on Friday at 5 PM and closed on Monday at 9 AM, will be a few hours rather than 3 days. It has various other reports like assignee time, status entry dates, average/sum reports(eg. average in progress time per project).

Here is the online demo link, you can see it in action and try.


If you are looking for a free solution, you can try the limited version Status Time Free.

0 votes

You'll need one of the scripting or automation apps to do this, and it won't work quite the way your describe. 

Cloud does not support "pre-fill" properly, there's no way for an app to inject the required code.  The best you can do is pre-calculate and fill in a custom field during an action such as edit or transition.

Pre-calculating you mean, estimating on our own and posting our estimation to "time spent" ?

 

Approx. like this:

Auto time spent:

{

"update": {

    "worklog" : [

      {

        "add": {

          "timeSpent" : "6m"

        }

      }

    ]

  },

    "fields": {

        "timetracking": {

              "originalEstimate": "10",

              "remainingEstimate": "5"

        }

    }

}

Thank you for your reply, understood.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events