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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

117 views 0 3
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