Using Groovy: How can I know if a customfield exists in an issue?


I,m writing a groovy script for creating an issue "Target_Issue"  in a project "Target_Project" based on an issue "Source_Issue" from another proyect "Source_Proyect".

There are some customfields that exists in "Source_Proyect" but not in "Target_Project".

My steps:

  1. To clone the "Target_Issue" using: 
    MutableIssue newMutableIssue = issueFactory.cloneIssue(myIssue);

  2. Reset some fields that don't must be set in "Target_Issue" using:
    newMutableIssue.setCustomFieldValue(customFieldXXX, null);

  3. Populate some fields that "should" exists in "Target_Issue" using:
    newMutableIssue.setCustomFieldValue(customFieldXXX, value);

Because the groovy script must woks for different pairs <"Target_Project" ,"Source_Proyect"> before reset and populate fields in "Target_Issue" I need to test if the customfield to be reset/populate exists in this issue.

How can I do that?


Thanks in advance




2 answers

1 accepted

1 vote
Accepted answer


This will list all custom fields in an Issue. 

List<CustomField>  allCustomFields = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue);

Some ideas?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,533 views 15 21
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you