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
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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,849 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot