Scriptrunner - using Issue.getModifiedFields() to interpret currently selected Resolution on screen

Aaron Holm February 5, 2021

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.

1 answer

0 votes
John Chin
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.
February 7, 2021

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events