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

Scripted Fields return Null with issue.getCustomFieldValue() when accessed via a post function where their dependant fields are present on the transition screen

    Details

    • Critical Points:
      0.7

      Description

      If a custom field that a scripted field refers to is on the transition screen of a particular transition or is updated during the transition, if you call issue.getCustomFieldValue() on the scripted field within a post function on that transition it will return null.

      If you have no transition screen where the user could alter the custom field before the transition occurs then the post function returns the value of the scripted field correctly.

       

      Steps to reproduce:

      1. Create a Date Time Custom Field named "DateTimeFieldA"
      2. Create a Scripted field named "SR DateTime" that refers to that same Date Time custom field and returns the string "Test: $valueOfDateTimeCustomField"
        import com.atlassian.jira.component.ComponentAccessor
        import com.atlassian.jira.issue.CustomFieldManager
        import com.atlassian.jira.issue.Issue
        import com.atlassian.jira.issue.fields.CustomField
        import org.apache.log4j.Logger
        import org.apache.log4j.Level
         
        def log = Logger.getLogger(getClass())
        log.setLevel(Level.DEBUG)
         
        Issue issue = issue
         
        String fieldName = "DateTimeFieldA"
         
        CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
         
        CustomField dateTimeField = customFieldManager.getCustomFieldObjects().find{it.name == fieldName}
         
        if(dateTimeField){
         
           def value = issue.getCustomFieldValue(dateTimeField)
           return "Test: $value"
         
        }else {
           return null
        }
        
      3. Create a "Send a custom Email" post function that refers to the value of the Scripted Field in the email template and also logs out its value.
        <ul>
          <li>Approved By: <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('DateTimeFieldA')) %></li>
          <li>Approved On: <%
            def org.apache.log4j.Category log = org.apache.log4j.Category.getInstance("com.onresolve.scriptrunner.canned.jira")
            log.setLevel(org.apache.log4j.Level.DEBUG)
           
          log.debug("inside template")
          log.debug("Before:" + com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('DateTimeFieldA').getValue(issue))
          def cfv = issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('SR DateTime'))
          log.debug("Scripted Field:" + cfv)
          out << cfv
          log.debug("After:" + com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('DateTimeFieldA').getValue(issue))%></li>
        </ul><br />
        
      4. Make sure there is a screen on this same transition. The "DateTimeFieldA" field must be on this screen.
      5. Transition an issue to trigger the above "Send a custom Email" post-function script but during the transition, change the "DateTimeFieldA" fields value on the transition screen
      6. When triggered the email post function will get a null for the value of the scripted field.
        DEBUG 2020-03-09 11:30:24,026 [onresolve.scriptrunner.canned.jira] inside template
        DEBUG 2020-03-09 11:30:24,027 [onresolve.scriptrunner.canned.jira] Before:2020-03-18 11:19:00.0
        DEBUG 2020-03-09 11:30:24,027 [onresolve.scriptrunner.canned.jira] Scripted Field:null
        DEBUG 2020-03-09 11:30:24,027 [onresolve.scriptrunner.canned.jira] After:2020-03-18 11:19:00.0
        
      7. The same result occurs if you do not change the "DateTimeFieldA" fields value on the transition screen. The field being present on the transition screen is enough to cause the above.
      8. If the user cannot change the "DateTimeFieldA" field during the transition if for example, there is no screen on the transition, then the post function can get the scripted fields value correctly.

       

       

       

       

        Attachments

          Structure

            Activity

              People

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

                Dates

                Created:
                Updated:

                  Structure Helper Panel