Hello,
I want to set a component value in a post-function of the creation of an issue.
Therefore, I created a groovy script in the post-function of the create issue that set a specific value to the issue.
If this specific value is not exists in the project component list, the script will create it first and then will set this component to the issue.
Here is my script:
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
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import org.apache.log4j.Logger
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)
MutableIssue myIssue = issue
Project project = myIssue.getProjectObject()
def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),'PSW')
//log.info("The Component is: " + theComponent)
if (theComponent == null) {
theComponent = ComponentAccessor.getProjectComponentManager().create("PSW","PSW component","",0,project.getId())
//log.info("The Component not exists")
//log.info(theComponent)
}
myIssue.setComponent([theComponent])
Something is not working here. The component is not set to the new issue, any idea why?
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
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import org.apache.log4j.Logger
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)
MutableIssue myIssue = issue
Project project = myIssue.getProjectObject()
def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),'PSW')
//log.info("The Component is: " + theComponent)
if (theComponent == null) {
theComponent = ComponentAccessor.getProjectComponentManager().create("PSW","PSW component","",0,project.getId())
//log.info("The Component not exists")
//log.info(theComponent)
}
myIssue.setComponent([theComponent])
myIssue.store()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this script. It works for me. Do not forget that only Project Administrator can create a component if the component is absent
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
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Logger
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
MutableIssue myIssue = issue
Project project = myIssue.getProjectObject()
def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),'PSW')
//log.info("The Component is: " + theComponent)
if (theComponent == null) {
theComponent = ComponentAccessor.getProjectComponentManager().create("PSW","PSW component","",0,project.getId())
//log.info("The Component not exists")
//log.info(theComponent)
}
myIssue.setComponent([theComponent])
ComponentAccessor.getIssueManager().updateIssue(user,myIssue,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.
I used this script, with
SCRIPTRUNNER and the predefined, Clones an issue, and links listner.
It works perfect after comment out
import org.apache.log4j.Logger
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)
ComponentAccessor.getIssueManager().updateIssue(user,myIssue,EventDispatchOption.ISSUE_UPDATED,true)
from the script above.
Thanks you very much
Alexey Matveev [cPrime]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is the post functin on creation? if so add issue.store()
And your post function must be before reindexing post function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you.
Where should I add it? (the issue.store())
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.