Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

scriptrunner post function : how to block transition

Fabrice Bovy
Contributor
June 29, 2017

How can I block/cancel transition if some customfield values are not correct like a startdate >= enddate ?

And of course, showing a message to the user.

Here is my script on the create event:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def dateDebRsv = customFieldManager.getCustomFieldObject("customfield_12100")
def dateFinRsv = customFieldManager.getCustomFieldObject("customfield_12101")
def dateMEP = customFieldManager.getCustomFieldObject("customfield_12102")
def dateDebGar = customFieldManager.getCustomFieldObject("customfield_12103")
def dateFinGar = customFieldManager.getCustomFieldObject("customfield_12104")

def dateDebRsvValue = issue.getCustomFieldValue(dateDebRsv)
def dateFinRsvValue = issue.getCustomFieldValue(dateFinRsv)
def dateMEPValue = issue.getCustomFieldValue(dateMEP)

if (dateDebRsv >= dateFinRsv)
{
	// Show error message
	// Block transition
}

if (dateMEPValue != null)
{
	issue.setCustomFieldValue(dateDebGar, dateMEPValue + 1)
	issue.setCustomFieldValue(dateFinGar, dateMEPValue + 15)
}

2 answers

1 accepted

0 votes
Answer accepted
Tarun Sapra
Community Champion
June 29, 2017

Hello Fabrice,

If you want to block/cancel a transition then you should use the "Validation" phase of the transition. As post-function phase means transition has already happened thus you should use the validation phase instead of post-function phase.

Fabrice Bovy
Contributor
June 29, 2017

Hi,

yes, I did that... and throw a new InvalidInputException to show error message.

thanks for your help.

0 votes
Sascha Ziemann
Contributor
October 15, 2021

Scriptrunner can not block a transition. But it is possible to block a transition in a post-function.

The add-on Jira Misc Workflow Extensions can cancel a transition. You just need to throw an exception. The only drawback is, that you can not format a custom error message. The user gets shown the exception.

Scriptrunner executes post-function asynchronously. This is the reason why the result of a post-function can not have any impact on the remaining post-functions. In my opinion this is a design error. It is inappropriate to do anything asynchronously in a transaction based system like a workflow engine.

Suggest an answer

Log in or Sign up to answer