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

Hi,

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

 

Begoña

 

2 answers

1 accepted

Hi, 

This will list all custom fields in an Issue. 

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

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,754 views 11 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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot