How do I add validation logic and message when selecting a particular component(s)?

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

2 answers

1 accepted

0 votes
Accepted answer

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.

 

1 vote

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 cheeky

 

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,512 views 15 20
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