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

Begoña Bonet March 3, 2015

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

2 votes
Answer accepted
Liston Ogana May 1, 2015

Hi, 

This will list all custom fields in an Issue. 

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

Begoña Bonet May 3, 2015

Thanks!!

0 votes
Begoña Bonet March 11, 2015

Some ideas?

Suggest an answer

Log in or Sign up to answer