Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

get value on null - script listener

Dan27
Contributor
September 3, 2018

Hi,

I have a code that takes a custom field value.

This custom field is 1 checkbox- "Yes".. If it chosen, the value is 'Yes' and if it doesn't, the value is null.

I use those lines:

def internal = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Internal Feature");

def selectedValues1 = internal.getValue(featureIssue);
def selectedValues2 = internal.getValue(issue);

 

When the value is null, The code didn't run, and send this error:

Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.getValueFromIssue(AbstractMultiCFType.java:150)
	at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.getValueFromIssue(AbstractMultiCFType.java:39)
	at com.atlassian.jira.issue.fields.ImmutableCustomField.getValue(ImmutableCustomField.java:350)
	at com.atlassian.jira.issue.fields.CustomField$getValue$1.call(Unknown Source)
	at Script1099.run(Script1099.groovy:52)

Can someone help me to understand how can I do it ? 

 

Tnx !

1 answer

1 accepted

1 vote
Answer accepted
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2018

Hello @Dan27

Use getCustomFieldValue() instead of getValue()

def internal = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Internal Feature");

def selectedValues1 = featureIssue.getCustomFieldValue(internal)
def selectedValues2 = issue.getCustomFieldValue(internal)

A what is in the line 52?

Dan27
Contributor
September 3, 2018

Thanks!!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events