Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • Can Jira workflow 'All' transitions be restricted for certain resolutions or statuses natively?

Using Script Runner to update Custom Field A with a timestamp when Custom Field B is updated

David Vaughan
April 14, 2023

My client wants to be able to create a filter for issues where Field A has been updated in the last 7 days. As Jira doesn't have the ability to filter for updates made to specific custom fields I am trying to set up another date custom field (Field B) and using a ScriptRunner Listener to add the date every time field A is updated.

I have used some of the logic provided in this post: https://community.atlassian.com/t5/Jira-questions/Scriptrunner-listener-to-update-custom-date-time-field/qaq-p/387444 

Specifically, the code below (although have changed the field names as needed). 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def cfm = ComponentAccessor.getCustomFieldManager()
def watch = cfm.getCustomFieldObjectByName("% Complete")
def watchValue = event.issue.getCustomFieldValue(watch)
def updatedWatch = cfm.getCustomFieldObjectByName("% Complete Updated")
def today = new java.sql.Timestamp(new Date().getTime())

if (event.getChangeLog().getRelated('ChildChangeItem').find{ it.field == '% Complete'}){

def changeHolder = new DefaultIssueChangeHolder()

updatedWatch.updateValue(null, event.issue, new ModifiedValue(null, today), changeHolder)

}
This seems to be working and whenever I update Field A, Field B is populated with the date. However, when trying to build a JQL search for "Field B" > -7d it is not returning results, and when I try "Field B" is not EMPTY I also get no results. However, if I search for the specific key of an issue with Field B populated I can see the date populated in the column. 

As a test, I manually updated Field B with tomorrows date which allows me to search for it in the issue navigator based on "Field B". I then updated Field A again which caused the Listener to update Field B with today;s date and viewing the issue in the issue navigator the date has been updated correctly to today's date. BUT, my JQL searches still seem to read it as tomorrows date, which I entered manually. 

The JQL search only seems to be able to interpret the data I have manually entered into the field, and disregards amendments made by the Listener. Have I missed something obvious in the Listener code or is it known behaviour that JQL cannot parse data entered onto a field by a ScriptRunner listener? 

2 answers

1 vote
Ivan Tovbin
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 Champions.
June 1, 2018

Hi Matthew,

'All' or 'Global' transitions can have the same conditions, validators and post functions like any other regular transition. So in your case you have set up a condition which would only allow this transition to be triggered if issue's resolution is set to 'Done'. More info on workflow transition conditions is in this documentation.

Matt
Contributor
June 1, 2018

Hi Ivan, Thanks for the quick reply.

From what I understand of the native conditions available for workflow transitions, they do not allow for a condition to be set so that only certain resolutions are deemed to be eligible for transition.

Which native condition would this be? As they all seem to be oriented towards restricting certain users, roles, or groups of users and not the issue status or resolution.

Thanks,

Matt

Ivan Tovbin
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 Champions.
June 1, 2018

Indeed, the list of conditions which is available out of the box is rather limited and does not really allow much flexibility.  

Fortunately however, many 3rd party plugins add many different validators, conditions and post functions. I would recommend JMWE for starters. It has a ton of built-in conditions and also allow you to write your own using Groovy scripts, if you feel like it.

Matt
Contributor
June 1, 2018

Thanks for the heads up regarding JMWE. It's a shame Jira does not allow this natively.

I have found that Scriptrunner also allows for the creation of custom conditions, and can be created based on JQL, such as Status != 'Unwanted status' etc.

Ivan Tovbin
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 Champions.
June 3, 2018

Scriptrunner allows you to write custom scripted conditions, which gives you a MASSIVE flexibility in choosing your options, so if you happen to have it, then it can easily solve your issue. If you need help with writing a script for your custom transition then do let me know, I might be able to assist.

0 votes
Goran Dermeta
November 7, 2019

Hi all,

I am having a similar issue, but only JMWE, no scriptrunner.

Is it possible to use Groovy to create one condition which allows only a specific project role to transition to Reopen?

 

Currently Reopen transition is global, and only assignee can use it. But I would like to limit use of this transition when resolution is set for a task, so that only project admin could reopen from statuses Resolved and Closed.

Can this be done with Groovy, and how to do it?

Goran Dermeta
November 7, 2019

It seems this Groovy solves my needs:

issue.getAsString("resolution") != ""
currentUser.isInProjectRole("Administrators", issue.get("project"))

Suggest an answer

Log in or Sign up to answer