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
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}"
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.ProjectComponentimport 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
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?
I have tried this method and worked for me
def lstCmp = issue.components.namedef lstCmp = issue.components.nameif(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 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 existsdef componentNames = issue.getComponents()*.name //get the name from each components//the following line does the exact same thingdef 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 scriptrunnerdef project = issue.projectObjectdef projectComponentManager = ComponentAccessor.projectComponentManagerdef allComponents = projectComponentManager.findAllActiveForProject(project.id)
It looks like you're new here. Sign in or register to get started.