Currently, to get a custom field object or value, I use such approach:
MutableIssue issue = issue
Long someCustomFieldId = 10206L
def object(Long customFieldId) {
ComponentAccessor.customFieldManager.getCustomFieldObject(customFieldId)
}
def value(Long customFieldId) {
issue.getCustomFieldValue(object(customFieldId))
}
return "Field object: ${object(someCustomFieldId)}, field value: ${value(someCustomFieldId)}"
But instead of calling object(someCustomFieldId) and value(someCustomFieldId), I want to use someCustomFieldId.object and someCustomFieldId.value
For implementing, I have created a class
class Field {
Long customFieldId
final object
final value
Field(customFieldId) {
this.customFieldId = customFieldId
}
def getObject() {
ComponentAccessor.getCustomFieldManager().getCustomFieldObject(customFieldId)
}
def getValue() {
issue.getCustomFieldValue(getObject())
}
}
def someCustomField = new Field(11002L)
Calling someCustomField.object returns a custom field object, but calling someCustomField.value does not return any value.
An error occurred:
groovy.lang.MissingPropertyException: No such property: issue for class: Field Possible solutions: value
How to get current issue object in a custom class?
This usually depends on where you are trying to get a handle on the issue. What is the context for the code you are running?
I need to operate with an issue fields values and/or objects.
Previously I defined all necessary custom field ID in Long format and used something like this:
def customFieldManager = ComponentAccessor.customFieldManager
Long businessEmail = 12345L
def businessEmailObject = customFieldManager.getCustomFieldObject(businessEmail)
def businessEmailValue = issue.getCustomFieldValue(businessEmailObject)
if (businessEmailValue) {
...
}
else {
issue.setCustomFieldValue(businessEmailObject, someValue)
}
It is ok, if I use 2-3 issue fields in my code. But in case of 10-20 fields it is not ok.
Therefore I want to use some simple and short approach for custom fields objects and values operations.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am sorry, I was not clear. What is the context the code will run in? What does a user do that makes it run?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, then
cf = customFieldManager.getCustomFieldBy<something-type>(<something-name>)
issue.getCustomFieldValue ( cf )
is the right approach. You'll get an object back which is of the type of the stored data (string, option, date/time, number etc). The <something-type> would be "by name" or "by ID", and you need to feed it the name or id of the field you want to get.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.