Uploaded image for project: 'SR for Jira - Development'
  1. SR for Jira - Development
  2. SRJIRA-4496

Provide an easy method to get the displayed value of a database Picker Scripted Field

    Details

    • Type: New Feature
    • Status: Triage (View Workflow)
    • Priority: Low
    • Resolution: Unresolved
    • Affects Version/s: 6.0.2, 6.4.0
    • Fix Version/s: None
    • Component/s: Scripted Fields
    • Labels:
      None
    • Critical Points:
      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.

        Attachments

          Structure

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              mclark Matthew Clark
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:

                  Structure Helper Panel