Auto-transition an issue when Remaining Estimate is 0

Patrick Richards July 17, 2013

I'm trying to set up an automatic transition for issues that get updated and have Remaining Estimates set to 0.

I'm using Script Runner and have tried adapting the script from this: https://answers.atlassian.com/questions/839/avoid-that-an-issue-gets-resolved-if-time-remaining-is-left-on-issue

I have the script set up as a Post Function and have verified that it does work when I set it to transition based on the condition where reporter == current user, but I can't get it to work based on values from any fields.

For the Condition, I have tried both

issue.estimate == 0

and

issue.timeestimate == 0

and nothing happens. But when I try

currentUser == issue.reporter

just to test, it works, so I know I at least have everything else set up.

Any help is greatly appreciated.

Thanks,

Pat

7 answers

1 accepted

1 vote
Answer accepted
Tanner Wortham
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 18, 2013

instead of a post-function, you should create a script listener that fires upon "Work Logged On Issue." a post-function fires upon issue transition, which isn't what you want. you want an issue transition when a work logged is entered. i don't have any listeners that do what you're doing, but here's one i use that makes a user a watcher after they've logged time to the issue.

package com.custom

import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Category
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.security.JiraAuthenticationContext

class WorkLoggedListener extends AbstractIssueEventListener {
    Category log = Category.getInstance(WorkLoggedListener.class)
 
    @Override
    void issueWorkLogged (IssueEvent event) {
    	log.setLevel(org.apache.log4j.Level.WARN)
    	log.debug ("----------- begin WorkLoggedListener --------------")
    	
    	ComponentManager componentManager = ComponentManager.getInstance()
    	WatcherManager watcherManager = componentManager.getWatcherManager()
    	JiraAuthenticationContext jiraAuthenticationContext = componentManager.getJiraAuthenticationContext()
    	watcherManager.startWatching(jiraAuthenticationContext.getLoggedInUser(), event.issue)
    	
    	log.debug ("----------- end WorkLoggedListener ----------------")
    }
}

Patrick Richards July 18, 2013

Thanks for this, I just confirmed that you're right that it works with a Work Logged event, which works perfectly for when a user uses the built-in "Log Work" option.

However, when I have a transition screen that has log work as just an option along with a bunch of other fields, it doesn't work.

I tried making the transition fire a "Work Logged On Issue" event and that doesn't work. I also tried making both the listener and the Post Function use "Issue Updated" events, and that doesn't work either...

So close... any ideas on how to make it work in the Post Function for a screen that has log work fields?

---

Just for reference for other interested people, it does work for users who use the built-in Log Work screen, with the listener set up on "Work Logged on Issue" event with the simple Condition:

issue.estimate == 0
Tanner Wortham
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 18, 2013

so you're saying that works for the typical time entries, but doesn't when they log their time on a screen between transitions, eh?

if that's the case, have a look at your workflow. if you look under the "post-function" section, you should see near the bottom that some kind of event was fired. It'll say something like "Fire a <something> event that can be processed by the listeners." whatever that something is is what you'd want to add to your listener. in other words, in addition to have some code for issueWorkLogged, you'd also want some similar (if not identical) code for that <something>.

you should also keep in mind that a transition to this final, closed state is necessary from your various statuses. your listener can't violate whatever workflow you've created. if it tries to, the listener will fail.

Patrick Richards July 18, 2013

You know what, I've been playing wiht this since you gave me the solution that works with the built in work logging, and I've reevaluated my workflow and think I will just segregate out the work logging from transition screens entirely. That keeps it cleaner (though it does add an extra step for the user). Thanks for your help though, very much appreciated!

0 votes
Patrick Richards January 5, 2014

Hey Justin,

Yeah, I never actually submitted the ticket until just now: https://jira.atlassian.com/browse/JRA-36373

I ended up keeping logging work as a separate action from the issue transitions. It's working fine for our purposes but obviously it would be great if this wasn't an issue because then we'd be able to eliminate one extra step for our users.

best,

Pat

0 votes
Tanner Wortham
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.
September 23, 2013

@patrick, assuming that the code is solid, the first thing that comes to mind is that there exists no transition from the status the user is in to whatever final status your code is advancing the issue to. Without such a transition, it'll fail every time.

Patrick Richards September 23, 2013

Thanks for the feedback. I understand what you're saying but what I was doing is modifying an existing working transition.

Here's the issue in detail.

This works:

  • On a working existing transition, I have a number of fields including "Remaining Estimate" BUT NOT "Log Work".
  • This transition fires a Generic Event
  • I have a "Fast-track transition an issue" script listener set up to listen for Generic Events where the condition is
    issue.estimate == 0
  • The script is designed to execute a separate (shortcut) transition that moves the issue to a closed status, when this condition is met.
  • This is done by the user changing the Remaining Estimate field to 0 in the original transition.

This does not work:

  • On a working existing transition, I have a number of fields including "Remaining Estimate" AND "Log Work".
  • This transition fires a Generic Event
  • I have a "Fast-track transition an issue" script listener set up to listen for Generic Events where the condition is
    issue.estimate == 0
  • The script is designed to execute a separate (shortcut) transition that moves the issue to a closed status, when this condition is met.
  • This is done by the user changing the Remaining Estimate field to 0 in the original transition.

This does not work:

  • On a working existing transition, I have a number of fields including "Remaining Estimate" AND "Log Work".
  • This transition fires a Log Work Event
  • I have a "Fast-track transition an issue" script listener set up to listen for Log Work Events where the condition is
    issue.estimate == 0
  • The script is designed to execute a separate (shortcut) transition that moves the issue to a closed status when this condition is met.
  • This is done by the user Logging Work that brings the Remaining Estimate field to 0 in the original transition.

hope that helps. It's really just that it works without the "Log Work" field on a transition screen but as soon as that's added it no longer works.

Tanner Wortham
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.
September 23, 2013

hmmm ... i'm at a loss then. it's good that you narrowed it down to the Log Work deal. why not open a ticket with Atlassian here? maybe it's a defect or maybe they'll be able to solve your problem.

Justin Leader
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 5, 2014

Hey Tanner and Patrick! Good discussion. Did you ever find a solution?

0 votes
Patrick Richards September 22, 2013

Ok, so I'm actually back to this again. I would really like to figure out why it won't work when it's part of a transition screen. For reference, I did change the Post Function to have the Work Logged on Issue event, and had the Script look for that event and it just doesn't work. I have tried Generic Event and Issue Updated too with no luck.

There seems to be some issue when you add Log Work to a transition screen where the Event that would normally be fired no longer is. Any ideas?

0 votes
Patrick Richards July 18, 2013

Yes, that's correct. I want to transition the issue when the remaining estimate gets to 0. Resolution isn't important in this case.

0 votes
Tanner Wortham
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 18, 2013

before i give an answer, i wanted to verify that i understood your situation correctly. in short, you're saying .... when remaining estimate reaches 0, mark issue as Done (with the default resolution).

0 votes
Patrick Richards July 18, 2013

FYI, I also tried this and it doesn't work either

import com.googlecode.jsu.util.WorkflowUtils
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import org.apache.log4j.Category
import com.opensymphony.workflow.WorkflowContext;
 
passesCondition = false

def remainingEstimate = issue.getEstimate();
if (remainingEstimate == 0) {
    passesCondition = true
}

Suggest an answer

Log in or Sign up to answer