I am using the ScriptRunner "Clone an issue, and links" post function.
I am trying to figure out what I need to add in the "Additional issue actions" section to create the issue in a project based on a project picker custom field.
E.g. Users can select the project they want to clone to during the transition and the issue will be cloned to that project.
How can users choose the project? Is it a custom field? This post function already creates an issue. Do you want to create another one?
It is a custom field that users can select on the workflow transition screen.
I only want to clone the issue once but I want the project key for the cloned issue to be based on the user selection (custom field)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see. It is not that simple to change the project key. You should not use the built-in function. You should create your own custom script, which would create an issue out of the source issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok. I have most of that working but I cannot seem to copy the issue comments.
Here is my code so far:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def cField = customFieldManager.getCustomFieldObject("Move to Project")
def originalIssueKey = issueManager.getIssueByCurrentKey(issue.key)
def destinationProjectKey = ComponentAccessor.projectManager.getProjectObjByKey(cField.toString())
def commentManager = ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(originalIssueKey)
cloneIssue(originalIssueKey, destinationProjectKey)
issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
void cloneIssue (MutableIssue issue, Project project) {
def params = [
issue : issue,
(CloneIssue.FIELD_TARGET_PROJECT) : project.key,
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
] as Map<String, Object>
new CloneIssue().doScript(params)
}
doAfterCreate{
for (Comment comment : comments)
{
commentManager.create(originalIssueKey, comment.getAuthorApplicationUser(), comment.getBody(), false);
}
}
doAfterCreate seems to be giving me some problems.
Also, since I am using the same code as the clone issue listener, what should I return so I can reference the new issue in the "doAfterCreate" block?
Lastly, I am running this code as a Scriptrunner action in the Automation Plug-in
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I never used ScriptRunner in automation plugin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is the same. I just lets me run any scriptrunner script I create as part of the automation tool. Think of it as a listener that fires whenever something happens in JIRA.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Phillip, Not sure if you figured this out but if your intent is to copy the comments over you can pass them in the params
def params = [
issue : issue,
(CloneIssue.FIELD_TARGET_PROJECT) : project.key,
**(CloneIssue.FIELD_COPY_COMMENTS) : true, **
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
] as Map<String, Object>
The doAfterCreate you would use stuff like Linking the two issue together or assigning watchers
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.