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 vote

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 Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

232 views 1 18
Join discussion

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