How to create custom validators - subtask must exist

I thought i might be able to use validators to ensure that i can enforce the existence of a subtask before an issue (story type) reaches a particular step in the workflow.

However the ADD VALIDATOR option is limited to 3 options below.

- Complete Session Validator Validates that all Bonfire test sessions related to this issue are complete.

- Permission Validator Validates that the user has a permission.

- User Permission Validator Validates that the user has a permission, where the OSWorkflow variable holding the username is configurable. Obsolete.

How do i get about creating a custom validator, and can the validation 'subtask must exist' be created? (ps: i checked conditions, but all conditions checks is the status of a subtask, so that if no subtask exists, status cannot be checked)

5 answers

1 accepted

I have a very similar validator implemented, but is not the same case. In my case the validator check if the task (have subtasks AND they are all closed ) OR ( no subtasks at all).

Try searching in marketplace, it seems a pretty common use case and you can get this done.

Or, you can create a plugin as a workflow validator, to check if there are subtasks. The code is somewhat like:

public class CheckSubtastks implements Validator {

	public void validate(Map transientVars, Map args, PropertySet ps) throws InvalidInputException, WorkflowException {

		boolean validate = false;
		Issue issue = (Issue) transientVars.get("issue");

		int subtareas = issue.getSubTaskObjects().size();


		if (subtareas == 0) {
			validate = false;
			throw new WorkflowException("Define some subtasks to go ...");
		}

	}
}

1 vote

You are on the right track - that's exactly what validators are for.

However, Jira does not ship with very many of them. Most of us install add-ons to get some of the more basic validators (that really should be included in the core in my humble opinion) - the Jira Suite utilities is the one I usually reach for first. There are a lot of other validators in the marketplace too.

If you can't find one that matches, then you'll need to write one. I do this in two ways:

1. Write one as a plugin

2. Add the script runner add-on - it provides a framework that saves you having to write all the structure around your own plugin, you can get stuck straight into the code.

Hi Laurence,

Through this plugin guide you can create your custom validator plugin :

https://developer.atlassian.com/display/JIRADEV/Workflow+Plugin+Modules#WorkflowPluginModules-Validators

in the validator , you can have your own logic of validation.

Another important: condition is basically used for user permission (through these we can specific who all can see the transition).

thanks guys,

i am so impressed by the quick feedback, so many times i got stranded with Atlassian generic answers, that totally beats it.

i am usually a bit dubious about finding 'solutions' to my issues on marketplace, but with the reassurance that it might be a common use case, i downloaded https://marketplace.atlassian.com/plugins/com.fca.jira.plugins.workflowToolbox.workflow-toolbox and that particular use case was in there, so that i didn't have to code at all!

Happy :)

ps: might not work for everyone as it is a paid solution, however i am on a community license, so that is good enough for me

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

793 views 3 11
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