Our developers use Tempo to track time on issues. We have a SR Custom Script validator present on our Resolve Issue transition that looks at previously logged time for an issue and any time that has been logged on the currently viewed resolution screen. If neither are present when an error is displayed. This code is currently working as intended:
// 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("Please log time for completed work.") }
My goal is to add additional logic to this code block that will suppress this logic when any resolution other than 'Done' is selected. I attempted to use Issue.getModifiedFields() with the issue's resolution, it does not appear to be working as I had hoped. I have struggled to determine what if any value gets pulled from the screen for Resolution. Here is an example of what I've tried. Please note that I've tried using the numeric value for Done along with calling it out as a string, neither is working for me. Here is an example of one of several ways I have attempted to write this:
// 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")
def resolution = mIssue.getModifiedFields().get("resolution")
if (resolution != 10000 && !timeSpent && !currentWorklog) { invalidInputException = new InvalidInputException("Please log time for completed work.") }
Can anyone offer any advice on whether this is a formatting issue or if I am possibly asking the impossible here? I haven't been able to locate any examples or questions regarding Issue.getModifiedFields() and the Resolution field.
I have also tried using Done, 'Done', and "Done" in place of 10000 along with using quotes when citing the numeric value. All scripts pass validation but fail to recognize when done has been selected for the resolution of an issue on the Resolve issue form.
Hi @Aaron Holm
Basically, you can check the new or old values modify from the getModifiedFields method.
For example, you can do something like this to get the new modified value:
...
...
// get the new modified resolution value
def resolution = mIssue.getModifiedFields().get("resolution").getNewValue()
def resolutionID = resolution.getId()
def resolutionName = resolution.getName()
...
...
I hope this works.
Online 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.