Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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
Community showcase
Published in Apps & Integrations

🍂📹 Apptoberfest demo contest roundup: vote for your favorite demos!

Hi Community! The submissions are in (and listed below) for the 🍻🍂Apptoberfest🍂🍻 Demo Competition and it’s time for you to place your votes for the best: Analytics & reporting app demo ...

233 views 6 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you