set Component in groovy script

Hi!

I have a some problem with my groovy script. I try to set component in post-function, but it doesn't work:

import org.apache.log4j.Category

log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") 


ComponentManager componentManager = ComponentManager.getInstance()
MutableIssue issue = issue
ProjectComponent component = componentManager.getProjectComponentManager().findByComponentNameCaseInSensitive("MyComponent")
issue.setComponentObjects([component.getName()])

6 answers

1 accepted

Hey Kate, I figured out the answer about two weeks ago. Sorry I didn't reply any faster!

Here is the script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.project.Project 

MutableIssue issue = issue

Project project = issue.getProjectObject()

def component = componentManager.getProjectComponentManager().findByComponentName(project.getId(),'ComponentName')

issue.setComponentObjects([component])

I guess it's alright :)

Thank you!

What happens? Do you get any errors in the logs? Does it save? I had to call issue.store() after all the set functions to get it to save.

Also check the order of your post function. It's important.

0 votes

If you have that as the first post-function, I think what you have is sufficient. But as Harry says... check the logs, add some debug.

Did you ever solve this? If you did I would like to know, as I'm facing the same problem at the moment.

Unfortunately, no..

Hi all,

hope anyone can help me.

I made a post funcion when a issue is created to assign a component if the issue reporter is someone specific.

It seems that everything work well but, when I open the issue, the component is unset.

Does anybody can help me?

Here is my post function:

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.user.ApplicationUser

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.issue.comments.CommentManager

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.util.ImportUtils

import com.atlassian.jira.user.util.DefaultUserManager

import com.atlassian.crowd.embedded.api.User

import com.atlassian.jira.project.Project

 

 

MutableIssue issue = issue

def projectComponentManager = ComponentAccessor.getProjectComponentManager()

def project = issue.getProjectObject()

 

def componentSicurezza = projectComponentManager.findByComponentName(project.getId(), "CSR Sicurezza");

def componentSistemi = projectComponentManager.findByComponentName(project.getId(), "CSR Sistemi");

def componentPuc = projectComponentManager.findByComponentName(project.getId(), "CSR PUC");

 

def reporter = issue.reporter?.name

 

if (reporter == "emailhandlerSicurezza") {

    issue.setComponentObjects([componentSicurezza])

}

if (reporter == "EmailSenderSistemi") {

    issue.setComponentObjects([componentSistemi])

}

if (reporter == "emailhandler") {

    issue.setComponentObjects([componentPuc])

}

 

issue.store()

Suggest an answer

Log in or Join to answer

Stay in touch

Be the first to know what's trending on Atlassian Community

Community showcase
Gregory Van Den Ham
Published Monday in Jira

Got TLSv1.2?

...connector settings, you'll see something like: <Connector SSLEnabled="true" if you don't see a line that says "ciphers=".....", you may have a problem. How to fix it? So you got a B on your...

139 views 4 2
Read article
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot