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
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 ----------------") } }
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
This does not work:
This does not work:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Tanner and Patrick! Good discussion. Did you ever find a solution?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that's correct. I want to transition the issue when the remaining estimate gets to 0. Resolution isn't important in this case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.