Hi,
I'd like to read value(s) from Components field and then embed them in my custom e-mail with scriptrunner.
How do I retrieve the values (this may be null, single or multiple values I guess)?
Thanks
I have tried this method and worked for me
def lstCmp = issue.components.name
def lstCmp = issue.components.name
if(lstCmp.contains("xyz")){
do something...
}
Hi Santosh,
What do you import?
I tried import com.atlassian.jira.issue.getComponents, but got the error
unable to resolve class
Any pointer?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can only import valid classes. Use the Atlassian JAVADocs documentation to see what is available: https://docs.atlassian.com/software/jira/docs/api/8.13.6/
But in many cases, the only import you need is the ComponentAccessor (this refers to the jira java component, not the project component)
getComponent() is a method of the com.atlassian.jira.issue.Issue class.
So if you have an issue object of that class (like you would in a workflow context in scriptrunner), then you can access that method either using the java long-form or the groovy way without needing to import anything.
//issue already exists
def componentNames = issue.getComponents()*.name //get the name from each components
//the following line does the exact same thing
def componentNames = issue.components.name //get the name from each components
But if you want to access a list of components for a project/issue, then you need some imports
import com.atlassian.jira.component.ComponentAccessor
//assumes the issue was already declared by scriptrunner
def project = issue.projectObject
def projectComponentManager = ComponentAccessor.projectComponentManager
def allComponents = projectComponentManager.findAllActiveForProject(project.id)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
issue.components or issue.getComponents() will give you an array of all the components. That array could be empty, with only 1 or many values.
There you can test for null, or size... or collect the list of names:
"$issue.key has the following components: ${issue.components*.name}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
Thank you for reply. So if I'd like to make a script which reads the components and appends it to summary, could it be:
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.component.ComponentAccessor
def component = issue.getComponentObjects()
issue.setSummary(issue.components*.name + " " + issue.summary)
Also how do I make a condition whether a spcific component is in the array? In case I'd like to perform different actions based on components
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It depends on the specifics of what you want to do. There are many ways to branch the logic of a groovy script.
For example:
if (issue.components.any(it.name == "my test value"){
//do something here
} else {
//do something else here
}
This may get complicated if you have multiple components. What will you do if 2 components that might cause 1 variation of the summary are present at the same time?
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.