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.
Community moderators have prevented the ability to post new answers.
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I'm facing the same issue. Have you found what is the difference of if the re-index solves the problem?
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure, but think it's worth to run JIRA re-index.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.