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


This will list all custom fields in an Issue. 

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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

523 views 1 18
Join discussion

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