Forums

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

Exclude fields from being copied when clonning an issue using groovy script

Oded Priva
Contributor
June 7, 2014

Hi,

I'm using script runner 'Clones an issue and links' to clone an issue.

How can I exclude cusotme fields and non custome fields from being cloned?

What is the syntax to use in the "Additional issue actions" box?

Thanks.

4 answers

2 votes
Paresh Gandhi
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.
June 30, 2014
if field is custom
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'CustomFieldName'}
issue.setCustomFieldValue(cf, null)

1 vote
JamieA
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.
June 8, 2014

You need to just null out the fields you don't want to copy, eg

issue.assignee = null

etc

Kate McAnespie
Contributor
July 1, 2015

It seems Sprint cannot be nulled out?

JamieA
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.
July 1, 2015

I would think it can... What code did you use?

Matt Shelton
Contributor
March 31, 2016

Jamie, did you ever determine if this was actually possible?

Kate McAnespie
Contributor
March 31, 2016

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'}
issue.setCustomFieldValue(cf, null);

JamieA
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.
March 31, 2016

Yes... just zero out any field you don't want copied.

Matt Shelton
Contributor
March 31, 2016

Thanks Kate - I ended up doing exactly that.

עדי וקנין May 16, 2018

Hi,

I also tried to apply this on the scriptrunner listener but it doesn't work. 

I copied kate lines to "Clones an issue, and links" additional. can you please explain how you did it?

Kate McAnespie
Contributor
May 16, 2018

Did you Define the Custom field manager first?

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'}
issue.setCustomFieldValue(cf, null);

עדי וקנין May 20, 2018

What am i doing wrong?

clonning without sprint.PNG

עדי וקנין May 23, 2018

Kate, can you help me please?

Tim Yuan September 9, 2019

i got same setting with your screen shot. 

Did u fix this issue? 

0 votes
Bob Swift
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.
June 7, 2014

Clone Plus Plugin for JIRA provides options for customizing clone operations including field excludes. This provides issue actions (not workflow functions) that can help with some team work flows that don't need to be associated with a issue transition.

Create on Transition Plugin for JIRA does provide workflow functions for creating issues and subtasks with control over which fields get copied to the new issue. Not exactly cloning but with most of the same capability.

0 votes
Nic Brough -Adaptavist-
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.
June 7, 2014

The clone in groovy effectively calls most of the internal Jira clone function, which really does just copy everything.

To clone an issue with fields being dropped, you'll need to write your own script that can pull data from an existing issue and use bits of it to create a new issue.

JamieA
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.
June 8, 2014

I'm not sure this is the case, not as I remember it anyway.

Suresh Bhandiwad
Contributor
September 11, 2019

Hi @Nic Brough -Adaptavist-,

Can you please help with the script for Jira cloud in postfunction or listener? The script in community more intended for Jira server.

I have two custom field which I want to exclude from being copied when cloned an issue in Jira cloud. 

Thanks,
Suresh

Nic Brough -Adaptavist-
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.
September 13, 2019

This is a comment on a 5 year old question, so everything is out of date.  Please ask a new question and describe your exact environment and what you want a script to do,

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events