Details
-
Type:
New Feature
-
Status: Done
-
Priority:
Low
-
Resolution: Done
-
Affects Version/s: 6.0.2, 6.4.0
-
Fix Version/s: 6.29.0
-
Component/s: Scripted Fields
-
Labels:None
-
Sprint:SR4J Sprint 101, SR4J Sprint 102
-
Story Points:1
-
Critical Points:6.1
Description
As a Scriptrunner User
I want a simple method to get the displayed value of a database picker field
So that I can use the common JIRA Java API method of getting custom field values "issue.getCustomFieldValue()"
Notes:
Currently, to get the displayed value of a database picker field you have to call several methods instead of calling only the commonly used Jira Java API method "issue.getCustomFieldValue()"
When you use "issue.getCustomFieldValue()" on a database picker it returns the ID value of the selected database item which represents the first column of the selected row, or rows if its a multi-picker.
For now, this is how you can get the string value of a database picker field:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem import com.atlassian.jira.issue.fields.layout.field.FieldLayoutManager import org.apache.log4j.Level import org.apache.log4j.Logger def log = Logger.getLogger(getClass()) log.setLevel(Level.DEBUG) Issue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TEST-1") CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() FieldLayoutManager fieldLayoutManager = ComponentAccessor.getFieldLayoutManager() String fieldNameA = "TestdbPicker" def dbPicker = customFieldManager.getCustomFieldObjects().findByName(fieldNameA) def idValue = issue.getCustomFieldValue(dbPicker) log.debug("idValue = " + idValue) FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue).getFieldLayoutItem(dbPicker.id) //if the field has a value on the issue if (idValue) { //get the value as displayed on the Issue. //We need to call .trim() to remove line breaks and spaces def valueForDbPicker = dbPicker.getViewHtml(fieldLayoutItem, null, issue) as String log.debug(""" ---- value with removed spaces and new lines = `${valueForDbPicker?.trim()}` value Data Type = ${valueForDbPicker?.getClass()} ---- """) }
This Feature request is for us to either make a way that allows getCustomFieldValue() to return the display value or to document the recommended method of getting the displayed value.