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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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)
}

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

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
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Do Not Lose your Customer’s Trust

Missing deadlines is one of the biggest problems every team lead wants to avoid when dealing with managed services. When the customer contracts your company to help with IT services it is expected th...

24 views 0 0
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you