Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner: How to set Summary and customer field value when clone with Scriptrunner

Yin Liang_XDevPod
Atlassian Partner
April 22, 2024

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>

 

 

2 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 22, 2024

Hi @Yin Liang_XDevPod

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

Yin Liang_XDevPod
Atlassian Partner
April 22, 2024

where to set summary and customfield value ?

Yin Liang_XDevPod
Atlassian Partner
April 22, 2024

ok , I see , to clone issue first then update it

 

def newClonedIssue = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)
def updatedExecutionContext = newClonedIssue.execute(inputs, executionContext)

 

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
May 3, 2024

Hi @Yin Liang,

Has your question been answered?

If yes, please accept the answer provided.

 

Thank you and Kind regards,
Ram

0 votes
Victor Law
Community Champion
April 22, 2024

Hi @Yin Liang_XDevPod

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.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events