How to create custom validators - subtask must exist

laurence bascle July 7, 2013

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

1 vote
Answer accepted
Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

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
laurence bascle July 7, 2013

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

1 vote
laurence bascle July 7, 2013

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

1 vote
Dipti Ranjan Behera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

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

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 7, 2013

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.

Suggest an answer

Log in or Sign up to answer