Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Select project based on custom field during Clone an issue, and links post function (Scriptrunner)


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.

1 answer

0 votes

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)

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.

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)

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

I never used ScriptRunner in automation plugin

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.

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 

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events