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

Database Picker script fields break when you replace their configuration scheme



    • Bug
    • Status: Triage
    • Medium
    • Resolution: Unresolved
    • 6.47.0
    • None
    • Script Fields
    • 2.3


      If you replace the configuration context that's associated with a Database Picker script field, the ID for the new configuration context won't be updated for the script field and it will throw an error when trying to retrieve results:

      Steps to Reproduce:

      • In a clean Jira instance, create a new project and a single issue within that project
      • Navigate to the Resources tab in the ScriptRunner admin section and create a new local database resource
      • Head over to the Fields tab and create a new Database Picker field, using the local DB resource you just made
      • Now, go to the Jira Custom Fields page, and add the field to the Screens associated with the project you created in the first step
      • From there, make your way to the Configuration Scheme page for your new DB picker
        • You can do this by clicking on the cog wheel to the right of the DB picker field on the Custom Fields page, and then clicking "Configure"
      • Once on the configuration scheme page, delete the existing global context, and create a new one in its place
      • Now, navigate to the "Search for issues" page, and attempt to use the Database Picker dropdown. 
      • Upon doing this, you should notice the aforementioned error appears under the select list for the field.


      This appears to happen because the ID for the configuration context doesn't get updated to match the ID of the newly created context, so the old ID is sent to the endpoint that handles the DB picker search functionality. This causes a permissions error to be thrown on the backend, breaking the field altogether and making it essentially unusable across the instance. 

      Possible Workaround:

      import com.onresolve.scriptrunner.fields.ScriptFieldConfigurationService
      import com.atlassian.jira.component.ComponentAccessor
      import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
      def scriptFieldConfigurationService = ScriptRunnerImpl.scriptRunner.getBean(ScriptFieldConfigurationService)
      def customFieldManager = ComponentAccessor.customFieldManager
      // You'll need to change 00000 to the ID of the Custom Field that you want to update
      def field = customFieldManager.getCustomFieldObject(00000)
      def scriptField = scriptFieldConfigurationService.getConfigFor(field)
      // You'll need to change 00000 to the ID of the Configuration Context Scheme that you'd like to use
      scriptField.fieldConfigurationSchemeId = field.configurationSchemes.find { scheme -> scheme.id == 00000}.id

      After updating the IDs used in the script to match your use-case, you can run this script in the Script Console to bring the Script Field config context ID and Custom Field config context ID back in sync with one another.




            Unassigned Unassigned
            aderossett Aidan Derossett
            0 Vote for this issue
            3 Start watching this issue