Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

"Error: Field Time Spent is required" when closing an issue

Facundo Colella July 13, 2020

Hello everyone!

We are trying to track time and made the "Time tracking" field mandatory to close an issue. The thing is, even if you do enter the time data, when you try to close the issue it fails with with the error "Field Time Spent is required", how can this be? and how can we fix it?.

Thanks so much!

4 answers

0 votes
Leslie C
Contributor
January 18, 2023

1.  Create a screen (I call mine "Log Work Screen"  The only fields I choose are Time Tracking and Log Work.  (Comment will automatically be added).  (No, you do not have to add this screen to your screen scheme.) 

2.  Edit your workflow: 

On the outgoing Transition, click "Edit" and enter your "log work" screen name.  

Publish your workflow.  

When the user attempts to transition, the Log Work screen will pop out.  In order to move forward, they will need to enter some time spent.  

SKAdmin
Contributor
January 24, 2024

Is it possible to check for logged time prior or within the transition? We have the same problem, I can only get it to check for prior or check for logged time during transition. 

The goal is to prevent an issue from being closed without logging any time, but we don't care if it was logged while in progress or logged when closed. Using Worklog Pro. 


This validator prevents transition if no time is logged on transition, will not catch if time was logged prior. 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.InvalidInputException

def mIssue = issue as MutableIssue

def currentWorklog = mIssue.getModifiedFields().get("worklog")

if ( !currentWorklog ) {
throw new InvalidInputException("Time Spent must be logged when issues status updated")
}


This one prevents transition if there is no time logged prior, but when you try to log time on the transitions it will blocks you. 

def timeSpent = issue.getTimeSpent()
timeSpent>=0 && timeSpent != null


Tried to combine the two didn't work either. 

SKAdmin
Contributor
January 25, 2024

Solved in case anyone else has the same situtation

// check if work has been entered into the Time Spent field
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

def mIssue = issue as MutableIssue
def timeSpent = mIssue.getTimeSpent()
def currentWorklog = mIssue.getModifiedFields().get("worklog")

if (!timeSpent && !currentWorklog) {
    invalidInputException = new InvalidInputException("Time must be logged in order to close.")
}
0 votes
Facundo Colella July 14, 2020

Hi @Ravya and @Trudy Claspill and thank you for your answers and your time.
We made a change in our approach and used a validator on the "Resolved to Closed" transition with the following: 
!!issue.timeSpent

But now it won't even ask if the field is set or not. We've also tried this:
issue.timeSpent != null && issue.timeSpent != ''

Just to be absolutely sure, but maybe we are going the wrong way.
What we want actually is to make it mandatory to haver the time logged before closing an issue.
Thank you!

Trudy Claspill
Community Champion
August 21, 2020

@Facundo Colella 

Are you trying to confirm that time has been logged against the issue at some point prior to the transition?

Or are you trying to confirm that more time is logged during the transition?

Or are you trying to establish a rule that requires time to be logged during the transition only when there has not been any time logged previously?

Facundo Colella August 24, 2020

Hi Trudy,

It is actually more simple, what we really need, is to forbid an issue from being closed if there is no time logged for it, doesn't matter when the time was logged, you just shouldnt be able to close it without some time logged.

Thank you!

Trudy Claspill
Community Champion
August 24, 2020

Our Jira instance doesn't include any add-ons that allow us to incorporate code into Validators. We just have basic Validator functionality available so I'm not able to experiment with the solution you've tried.

The trick is to ensure your Validator is looking at data stored in the issue already, versus looking at changes being made to the issue during the transition. Time Spent is an unusual field in that there is the Time Spent field that you could be filling in when making the transition (adding more Time Spent to the issue) and there is also the accumulated Time Spent recorded for the issue. What you really need to check is the accumulated Time Spent. What might be happening is that it is trying to validate that more data is being entered for Time Spent during the transition.

Unfortunately I don't have the tools/apps necessary in my JIRA instance to figure out how to do what you want. At another employer I had access to Adapativist's ScriptRunner for JIRA, which might be a tool that could help. I recall that we could run Groovy scripts using that tool, and look at other information already recorded in the issue.

Facundo Colella August 24, 2020

Hello Trudy,

Thank you for your insight, I'll look into it, don't really know how to target the correct field if that was indeed the case, but I'll investigate about it.

Thanks again for your help!

Trudy Claspill
Community Champion
August 26, 2020

I'm not sure if there is an actual field that stores the total time spent, or if that is calculated in real time based on the individual Work Logs.

Like Facundo Colella likes this
junxian diao
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 15, 2020

this code works fine.

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.InvalidInputException

def mIssue = issue as MutableIssue

def currentWorklog = mIssue.getModifiedFields().get("worklog")

if ( !currentWorklog ) {
throw new InvalidInputException("Time Spent must be logged when issues status updated")
}

  

0 votes
Trudy Claspill
Community Champion
July 13, 2020

Exactly what did you do to make the "Time Tracking" field mandatory?

Did you change the Field Configuration to make "Log Work" required instead of optional? Or are you using a Validator in the workflow transition for closing the issue to ensure the field is not empty?

Tal Tzeytlin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 24, 2020

Validator

0 votes
Ravya
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.
July 13, 2020

Hi @Facundo Colella ,

I guess the condition was set in such a way that even though the spent is filled, it should be changed during the transition.

So once recheck the comdition.

--Ravya

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events