Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Difference between customField.getValue(issue) and issue.getCustomFieldValue(customField)?

vsoued April 17, 2015

Is there a crucial difference here that I'm missing? I have cases where customField.hasValue(issue) returns true, but issue.getCustomFieldValue(customField) returns null, and customField.getValue(issue) returns the correct value. It has also happened that customField.getValue(issue) returns null and issue.getCustomFieldValue(customField) returns the value. Note that both cases occur after having called customField.hasValue(issue) and it returning true.

This inconsistency started only recently, probably after a JIRA update.

5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Rustem Zinnatullin October 25, 2018

Seems like issue.getCustomFieldValue(customField) gets value directly from issue instance, and customField.getValue(issue) gets value from the database. So if you're developing, for ex, a worlflow validator, then in validate method you'll get different values if the custom field's value was changes in the transition screen, but not yet saved to the database. The EagerLoadingOfBizCustomFieldPersister class is used to get custom field value. Note that it also has a cache.

 

However, with system fields this doesn't work like that. For ex, if you've got AbstractTextSystemField instance for 'Description field, and call abstractTextSystemField.getValueFromIssue(issue), then it will get value directly from issue, just calling to issue.getDescription().

 

Experts, can someone please explain why there is such an inconsistency?

0 votes
Oles Hnatkevych (Princip-IT) May 25, 2018

There's a huge difference, and it is documented. 

getValue
Object getValue(Issue issue)
Retrieves and returns the Object representing the this CustomField value for the given issue. See CustomFieldType.getValueFromIssue(CustomField, Issue). This is only used to communicate with the 'view' JSP. Multiselects will return a list, dates a date, etc.

I always use issue.getCustomFieldValue(cf), never had problems with it.

0 votes
vsoued June 6, 2016

@Leandro Coutinho, kind of. The cases where I was getting null when there was actually a value were because I was calling issue.getCustomFieldValue(customField) in the middle of an issue transition (in a workflow post-function) which had a screen that didn't have the customField from which I was trying to get a value, therefore I was getting null. This was solved by adding the customField to the transition screen.

It seems to me that customField.hasValue(issue) and customField.getValue(issue) access the actual value stored for the customField while issue.getCustomFieldValue(customField) gets the value from the given issue instance, which in my case was given to the post-functions' execute, and only had the values included in the transition's screen. 

Let me know if I can be of more help.

0 votes
Leandro Coutinho June 6, 2016

Hi, I'm facing the same issue. Have you found what is the difference of if the re-index solves the problem?

Thanks.

0 votes
Volodymyr Krupach
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.
April 17, 2015

Not sure, but think it's worth to run JIRA re-index.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events