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()])
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])
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you end up solving your issue where you were trying to set different component values based on the person submitting the issue?
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm sorry, I resolved it using a post funcion based on issue type. The post funcion is set as first post funcion, befor the "Creates the issue originally" postfuncion.
In this way the component is set before the current.issue is created.
Here is the post funcion:
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 Servizio Tecnico");
def issueType = issue.issueTypeObject.name
if (issueType == 'Task CSR Servizio Tecnico') {
issue.setComponentObjects([componentPuc])
}
if (issueType == 'Task CSR Sicurezza') {
issue.setComponentObjects([componentSicurezza])
}
if (issueType == 'Task CSR Sistemi') {
issue.setComponentObjects([componentSistemi])
}
You can may try set the component based on the reporter setting the post funcion after the "create issue originally".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks! I was hoping to find a way to do this without having to define each component we want to set first and then make a statement saying change to this defined component, but it doesn't look like there is a way to do that. At least not in my searching.
We'll give this a shot and see if it will work for us. The biggest issue is we have 10 different components we are setting with the core part of the script.
Thanks Again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm on Jira Service Desk Server and the editor doesn't like
issue.setComponentObjects
If I use issue.setComponent the editor doesn't get mad, but it also doesn't do anything with it.
I tried putting the post-funtion (inline script) both before and after "Creates the issue originally." The script just fails when it's before "Creates the issue originally." It will at least add the placeholder comments I have if I put the inline script as the second option in the order that the post-functions occur.
Here is our post-function. I had tested this with comments at first since those are more accessible.:
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.jira.project.Project
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//Declaring Description field
def description = issue.description
//Declaring MutableIssue
MutableIssue issue = issue
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def project = issue.getProjectObject()
//Declaring the Department field and the value of the department field
def Department = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10501")
def DepartmentValue = (String)issue.getCustomFieldValue(Department);
//Check to see if component is already set
if (issue.getComponents().size() != 0) {
commentManager.create(
issue,
user,
"The component is already set", true)
}
//Set components for issues and emails that have component= in the body
if (description.contains("Component=")) {
commentManager.create(
issue,
user,
"The component is listed in the description", true)
}
//Sets component CHAS Tech
if (DepartmentValue == "Art") {
def CHASTech = projectComponentManager.findByComponentName(project.getId(),'CHAS Tech');
issue.setComponent ([CHASTech])
}
//Comment to help with troubleshooting how broke the previous script is/n't working
commentManager.create(
issue,
user,
"Comment that appears when the script runs.", true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Do we have any news regarding setComponentObject?
I am using jira server. Same issue here, setComponentObject is not considered as an existing method.
Regards,
Nima
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This worked for what we are doing:
def Tech = projectComponentManager.findByComponentName(project.getId(),"Tech"); issue.setComponent ([Tech]) ComponentAccessor.getIssueManager().updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.