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

This widget could not be displayed.

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!

This widget could not be displayed.

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.

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

Unfortunately, no..

This widget could not be displayed.

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
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

106 views 0 3
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