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

Default custom field values not set in sub-task created by Create Sub-task post-function

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Done
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 5.1.0
    • Fix Version/s: 5.4.34
    • Component/s: None
    • Labels:
      None
    • Environment:

      ScriptRunner| 5.1.0 |

      JIRA Software| 7.4.3 |

    • Critical Points:
      1

      Description

      In JIRA you have the ability to automatically set default values for your custom fields via the custom field configuration page. However, if you set a custom field to have default values, they will not be set when creating a sub-task via the ScriptRunner Create Sub-task post-function as you would expect.

      Steps to reproduce:

      • Create a new custom checkbox field and give it some random options.
      • Then configure that checkbox field to only appear on sub-tasks and set the default value of the field:

      • Now configure a Create Subtask post-function that executes on a transition of your choice.
        • Remember to publish the workflow before exiting
      • Create a new issue for testing
      • On your newly created issue, click the "More" tab and open the dialog to manually create a subtask. Notice that the values for your custom field are set to the defaults as you would expect.
      • Exit that dialog without creating a sub-task and then execute the transition that you attached the Create Sub-task post-function to.
      • Notice in the newly created subtask that the default values were not set!

      Workaround

      In the additional issue actions field, include the following script

      import com.atlassian.jira.component.ComponentAccessor
      import com.atlassian.jira.issue.context.IssueContextImpl
      
      def issueContext = new IssueContextImpl(issue.projectId, issue.issueTypeId)
      
      def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("CustomFieldName")
      def fieldConfig = ComponentAccessor.fieldConfigSchemeManager.getRelevantConfig(issueContext, cf)
      def defaultValue = cf.getCustomFieldType().getDefaultValue(fieldConfig)
      
      issue.setCustomFieldValue(cf, defaultValue)

        Attachments

          Activity

            People

            Assignee:
            tbatagiannis Thanos Batagiannis
            Reporter:
            aderossett Aidan Derossett
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: