I'm developing a workflow validation on the initial transistion "create issue" to check for the component selected. I've tried to use issue.componentObjects*.name.contains('component name') and issue.components*.name.contains('component name'), both dont work. What am I doing wrong?
The main purpose is to provide an error message when the wrong component is selected for a certain condition like by issue type. I can't get pass the component selection. It seems to be not working like sample below.
Script Validator -> Simple scripted validator -> Condition:
issue.componentObjects*.name.contains('component')
OR
issue.components*.name.contains('component')
Hi Matheus,
I guess the script could not be simplified...Your suggestion of iterating through the component object works for my validation condition code. I used the Component description to categorize the type to match issue type.
The validation code below returns true when the selected component is allowed for the Issue type.
int allowed_cnt=0;
if (issue.componentObjects.size() >= 1){
for (int i = 0; i < issue.componentObjects.size(); i++) {
if(issue.componentObjects.getAt(i)?.getDescription() == "A Component Type" && issue.issueTypeObject.name == 'A Issue Type'){
allowed_cnt++;
} else if(issue.componentObjects.getAt(i)?.getDescription() == "B Component Type" && issue.issueTypeObject.name == 'B Issue Type'){
allowed_cnt++;
}
}
if (allowed_cnt >= 1){
return true;
} else {
return false;
}
} else {
return false;
}Thanks.
Try iterating through
issue.getComponentObjects()
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
//Gets the Components List (Collection<ProjectComponent>)
def components = issue.getComponentObjects()
if (components.size() >= 1){
checkComponents(components, cf)
} else {
return
}
def checkComponents(def components, def cf){
for (int i = 0; i < components.size(); i++) {
if(components.getAt(i)?.getComponentLead() == "MyComponent"){
return false
}
}
}I have no idea if this will actually work, but it may be worth the shot ![]()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Matheus for your suggestion...I will give it a try but it seems to be complicated. I'm looking for a simple scripted validator condition code in the workflow validation on create. Also, I'm not checking for the component lead and more on the component name.
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.