Insight post function condition: How can I set only EMPTY custom fields from an attribute?

Hello,

I am trying to set up a post function that sets a JIRA custom field with the attribute value from a selected object, but only if that custom field is already empty. If it it empty, the post function should be skipped. I currently have this entered in the Condition box:

import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_xxxxx")
issue.getCustomFieldValue(cf) = null

I have had some success with this condition in the past if I use "!= null" but can't ever get the condition to recognise an empty custom field or a specific value.

Does anyone know where I've gone wrong?

3 answers

Hi,

The import statement is wrong with the ComponentAccessor. This is how it should look:

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_xxxx");
if (issue.getCustomFieldValue(cf) == null) {
    // Do something
}

Same answer as above...

Same answer as above...

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
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

355 views 0 6
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