How to skip Sprints when cloning an Issue using Scriptrunner?

Joern Jochims
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 2, 2024

Based on the code snippet provided by Adaptavist here, I am trying to configure the clone process in more detail. 

These are the current settings:

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)        : cloneComments,
    (CloneIssue.FIELD_USER_KEY)             : null,
    (ConditionUtils.FIELD_ADDITIONAL_SCRIPT): ['', ''],
    (CloneIssue.COPY_CUSTOM_FIELDS)         : true,
    (CloneIssue.FIELD_COPY_SUBTASKS)        : cloneSubTasks,
    (CloneIssue.FIELD_LINK_TYPE)            : linkBetweenIssues
] as Map<String, Object>

def executionContext = [issue: originalIssue] as Map<String, Object>
def cloneIssueAction = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)
// Execute the clone action with the specified params
def updatedExecutionContext = cloneIssueAction.execute(params, executionContext)

The clone process is part of a custom REST Endpoint and the parameters targetProjectKey, cloneComments, cloneSubtasks and linkBetweenIssues are provided from the call to this endpoint.

In the new issue created by the clone operation, all fields are copied just as desired, including all custom fields.

Now I want to add an additional option for the users to either copy the Sprints of the original issue or to delete all Sprints from the issue. My approach for the latter option was to perform the clone and then delete all Sprints from the newly cloned issue. However, Jira does not allow to remove completed Sprints from an issue, only active and future sprints, so the completed Sprints remain in the newly created issue with no way to remove them.

Is there any way to configure the clone process, so that the Sprints are not even cloned in the first place? (The standard "Clone" button in Jira provides this possibility).

I found the option:

 

CloneIssue.SKIPPED_CUSTOM_FIELD_DESCRIPTOR_KEYS

But I just could not get this option to work, so that the Sprints are not copied. Sadly, there is no documentation for the clone process above to further help me out, so I hope that anyone has a suggestion on how to configure this properly.

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Sergei Troshin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2024

Hi @Joern Jochims

I have not encountered the use of this ScriptRunner classes. I usually use the standard IssueFactory and IssueManager to create tasks.

However, I did a little investigation and found out that you can list the required fields manually in the CloneIssue.FIELD_SELECTED_FIELDS parameter.

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)      : ["description", "summary", "customfield_10501"],
    (CloneIssue.FIELD_COPY_COMMENTS)        : false,
    (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>

In this case, you will only copy summary, description and customfield with id = 10501

Joern Jochims
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 7, 2024

Hi @Sergei Troshin ,

thanks for your reply. I was hoping to be able to exclude specific fields from the copy process, but this does not seem to be possible.

I now create a list containing all system fields and all custom fields for the issue and then remove all fields I want to skip fom this list and hand it over to the clone function as you did above. This seems to run fine for now, so I will probably go with this solution.

DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events