scriptrunner post function : how to block transition

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)
}

1 answer

1 accepted

0 votes
Accepted answer
Tarun Sapra Community Champion Jun 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.

Hi,

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

thanks for your help.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,922 views 19 22
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you