Hi there Atlassian community/ ScriptRunner peeps,
Hoping to get some assistance in figuring out how to properly code the following...
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
}
Why don't you use the built-in function and use the additional issue actions to change the project from the default selected in the form?
import com.atlassian.jira.project.ProjectImpl
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Supporting Project'}
def project = sourceIssue.getCustomFieldValue(cf) as ProjectImpl
issue.setProjectObject(project)
@PD Sheehan - I didn't think it was possible since there is a drop down to choose the project...I'll give it a try. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@PD Sheehan Thank you soooo much for providing that fix! Working perfectly - appreciate the assistance!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To be honest, I did not test this and wasn't 100% certain it would work. But based on the documentation saying "if you want to override some of the field values rather than have them inherited from the source issue you can specify that in the Additional Code" I was pretty confident it would work.
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.