Hi there Atlassian community/ ScriptRunner peeps,
Hoping to get some assistance in figuring out how to properly code the following...
- I created a Custom web section and a Constrained create issue dialog that creates a Support Request issue type (working perfectly with the behaviour I've got along with it)
- Once the Support Request is 'ACCEPTED', I want to clone the Support Request as a task in the 'acceptors' project (I can't use the pre-scripted post function to clone issue since I need it to go to different projects based on info in the Support Request).
- I have a custom project picker field that I'm using on the Support Request issue type screen (this is what I want to use to tell jira what project I want the cloned issue created in)
- I've found code from SR that works if I define the issue I want cloned and the specific project to create it in
- I've found code that doesn't quite work to take that a step further and use the project picker field to designate which project to create the cloned issue in
Here's the code that I've mushed together...and it's not working. Hoping someone can provide some add'l insight.
Thanks in advance
//Pulled from SR script found online recipe
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.onresolve.scriptrunner.canned.jira.utils.AbstractCloneIssue
import com.onresolve.scriptrunner.canned.jira.utils.CannedScriptUtils
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import groovy.xml.MarkupBuilder
//pulled from atlassian user
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def cField = customFieldManager.getCustomFieldObject("Supporting Project")
def originalIssueKey = issueManager.getIssueByCurrentKey(issue.key)
def issueToClone = issueManager.getIssueByCurrentKey(issue.key)
def destinationProjectKey = ComponentAccessor.projectManager.getProjectObjByKey(cField.toString())
def commentManager = ComponentAccessor.getCommentManager()
def issueToClone = ComponentAccessor.issueManager.getIssueByCurrentKey(issue.key)
def linkBetweenIssues = CannedScriptUtils.getAllLinkTypesWithInwards(true).find { it.value == "support work" }?.key?.toString()
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_TARGET_ISSUE_TYPE) : '3',
(CloneIssue.FIELD_COPY_FIELDS) : AbstractCloneIssue.COPY_ALL_FIELDS,
(CloneIssue.FIELD_SELECTED_FIELDS) : null,
(CloneIssue.FIELD_COPY_COMMENTS) : true,
(CloneIssue.FIELD_USER_KEY) : null,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): ["", ""],
(CloneIssue.FIELD_LINK_TYPE) : linkBetweenIssues
] as Map<String, Object>
def executionContext = [issue: issueToClone] as Map<String, Object>
def cloneIssueAction = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)
// Execute the clone action with the specified params
def updatedExecutionContext = cloneIssueAction.execute(params, executionContext)
// Return the link to the cloned issue
cloneIssueAction ? "Cloned issue: ${createHrefLinkToIssue(updatedExecutionContext.newIssue as String)}" :
"Could not clone issue, check the logs for errors"
static String createHrefLinkToIssue(String issueKey) {
def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def writer = new StringWriter()
def html = new MarkupBuilder(writer)
html.html {
a href: "$baseUrl/browse/$issueKey", issueKey
}
writer
}