In my project AB i have two issuetypes
also i have losts of components
So the problem is to write correct validator for such rule:
with issuetypeA can be used only components which starts from or containce component name ("component name for A part 1" for example)
import com.atlassian.jira.component.ComponentAccessor;
if(issue.projectObject.name == 'AB' && issue.issueType.name == 'issuetypeA')
def components = issue.getComponentObjects();
if (components != null && "component".equals(components[0].getName()) {
return true;
}
return false;
But its fail
Jira v7.5.0 and Adaptavist ScriptRunner for JIRA 5.2.2
import com.opensymphony.workflow.InvalidInputException;
import com.atlassian.jira.component.ComponentAccessor;
if(issue.issueType.name == 'yourIssueType' && issue.projectObject.key == 'projectKey'){
if(issue.components*.name =~ /component starts from/){
return true;
}
else {
throw new InvalidInputException("components", "Use component 'component starts from...'");
}
}
Try you code like this
import com.atlassian.jira.component.ComponentAccessor;
if(issue.projectObject.name == 'AB' && issue.issueType.name == 'issuetypeA') {
def components = issue.getComponentObjects();
if (components != null && "component".equals(components[0].getName())) {
return true;
}
}
return false;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you just test whether the name of the first component in the issue equals "component". But as none of the names of your components is equal to "component", the test will always fail.
In addition, you test only the first component of the issue, I guess you should validate them all ??
And finally your validation will fail for all projects different from 'AB' and all issue types different from "issueTypeA"; i guess this is not wanted neither ???
Code (you can write this in a much more condensed form in Groovy, but I think it is easier to understand this way):
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.project.component.ProjectComponent
if(issue.projectObject.name == 'AB' && issue.issueType.name == 'issuetypeA') {
for (ProjectComponent component in issue.getComponents()) {
if (!component.name.startsWith("component name for A")) {
return false;
}
}
}
return true;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have logic like this
I have specific issue type and components
With this issue type i need to use only specific components.
So I need validation for this case
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
? Don't understand ? The answer is in my previous reply ???
What is still not working ???
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor;
if(issue.projectObject.name == 'AB' && issue.issueType.name == 'issuetypeA') {
def components = issue.getComponents();
if (components != null && "component".equals(components[0].getName())) {
return true;
}
}
return false;
Nope, its not works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.