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) }
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.