How to write a validator in JIRA?

Nils Lange November 26, 2013

Hello All,

I want to write validator that check if all linked issues have one special resolution.

I have tried using "Script Validator" but I don't know how to do this.

Can anyone help me?

Greetz Nils

2 answers

0 votes
Bharadwaj Jannu
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.
November 26, 2013

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

Using the following code you approach further

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.issue.link.LinkCollection;
import java.util.Collection;
import com.atlassian.jira.issue.Issue;
import com.opensymphony.workflow.InvalidInputException;
IssueLinkManager ilm=ComponentAccessor.getIssueLinkManager();

JiraAuthenticationContext authContext=ComponentAccessor.getJiraAuthenticationContext();

LinkCollection lc=ilm.getLinkCollection(issue, authContext.getLoggedInUser());

Collection<Issue> issues=lc.getAllIssues();
InvalidInputException e=new InvalidInputException();
for(Issue issue: issues)
{
   if(issue.getResolutionObject().getName().equals("<specific name>")==false){
e.addError("Resolution should be <specific name> for all linked issues");
   throw e;
}
}

you can do more customizations like by placing all issues in a collection(which are having resolution other than your specific name) and throw as error message.

Also go through my answers in

https://answers.atlassian.com/questions/219767/form-validation#comment-219826

https://answers.atlassian.com/questions/225982/simple-script-validation#226000

https://answers.atlassian.com/questions/217915/how-do-i-allow-a-transition-to-resolved-only-if-all-the-sub-tasks-are-closed-resolved#217941

0 votes
Bhushan Nagaraj
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.
November 26, 2013

Hey Nils,

You can use these tutorials here to write your own plugin validator.

http://jiradev.com/workflow-validator.html

https://www.j-tricks.com/1/post/2010/08/workflow-validator.html

If not use the script runner plugin

Your code will look something like this.

Collection<IssueLink> links = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());

for(IssueLink link:links){

Issue linkedIssue = link.getSourceObject();

if(linkedIssue.getResolutionObject().getName().equals("Something")){

return false;

}

}

Cheers

Bhushan

Suggest an answer

Log in or Sign up to answer