I would like to use the below script to clone issue
Copy an Issue to a New Project and Link to the Original - Adaptavist Library
Nevertheless how to change the summary of cloned issue during clone by :
com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
I didn't find the corresponding parameters such as
def params = [
(CloneIssue.FIELD_TARGET_PROJECT) : targetProjectKey,
(CloneIssue.FIELD_TARGET_ISSUE_TYPE) : null,
(CloneIssue.FIELD_COPY_FIELDS) : AbstractCloneIssue.COPY_ALL_FIELDS,
(CloneIssue.FIELD_SELECTED_FIELDS) : null,
(CloneIssue.FIELD_COPY_COMMENTS) : false,
(CloneIssue.FIELD_USER_KEY) : null,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): ["", ""],
(CloneIssue.FIELD_LINK_TYPE) : linkBetweenIssues
] as Map<String, Object>
For your requirement, I suggest simplifying your code using ScriptRunner's HAPI feature.
You could try something like this:-
import com.adaptavist.hapi.jira.issues.Issues
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
def projectKey = 'EX'
Issues.search('project = MOCK').each {
def issueToCopy = Issues.getByKey(it.key)
def blockIntraprojectLinks = '{l -> l.sourceObject.projectObject != l.destinationObject.projectObject}'
if (!issueToCopy) {
log.warn "Issue ${issueToCopy.key} does not exist"
return
}
def inputs = [
(CloneIssue.FIELD_TARGET_PROJECT) : projectKey,
(CloneIssue.FIELD_LINK_TYPE) : null,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): ["checkLink = $blockIntraprojectLinks;", ""],
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
(CloneIssue.SKIP_EPIC_LINKS) : "false",
] as Map<String, Object>
def executionContext = [issue: issueToCopy] as Map<String, Object>
def newClonedIssue = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)
def updatedExecutionContext = newClonedIssue.execute(inputs, executionContext)
assert updatedExecutionContext.newIssue
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
where to set summary and customfield value ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok , I see , to clone issue first then update it
def newClonedIssue = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)
def updatedExecutionContext = newClonedIssue.execute(inputs, executionContext)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Yin Liang,
Has your question been answered?
If yes, please accept the answer provided.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since you use the following parameters, it will clone all the fields in the source Jira issue.
(CloneIssue.FIELD_COPY_FIELDS) : AbstractCloneIssue.COPY_ALL_FIELDS,
You may add a script to set a new value in the Summary field after the clone action as a workaround.
Alternatively, you can implement a similar script as stated in the following document that sets the value of the Summary field during the issue clone process:
https://library.adaptavist.com/entity/basics-clone-issue
Thank you.
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.