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

Field server-side behaviour scripts trigger when create/edit window opened before the user has interacted with the field

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Done
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 5.5.2.1-jira8
    • Fix Version/s: 6.25.0
    • Component/s: Behaviours
    • Labels:
    • Sprint:
      SR4J Sprint 80, SR4J Sprint 81, SR4J Sprint 82, SR4J Sprint 83, SR4J Sprint 84, SR4J Sprint 85, SR4J Sprint 86, SR4J Sprint 87, SR4J Sprint 88, SR4J Sprint 89, SR4J Sprint 92, SR4J Sprint 93, SR4J Sprint 94, SR4J Sprint 95, SR4J Sprint 96, SR4J Sprint 97
    • Critical Points:
      19.3

      Description

      When opening the create/edit form, the event for user interaction on forms fields gets triggered even if the user has not selected that field with for example mouse input and therefore the server-side script is triggered without the user interacting with the field.

       

      This means that the initialiser and the field level server side script would trigger as soon as the create/edit window is opened rather than just the initialiser.

      Use case:

      User is attempting to set the assignee field to the logged in user in the initialiser for create screens, and in the server side script is making sure that if the user chooses "automatic" (i.e. -1) then an error is set on the field.

      You will end up with the assignee field being changed to the value from the initialiser but at the same time an error is set on the assignee field because both scripts are triggered when the create form loads, and the value for the assignee field is -1 until the user has manually changed from interacting through the UI.

      When we set the assignee field in the initialiser, it does not register as changed when the field server side script runs and therefore the field script reads the value -1

      Steps to reproduce:

      1. Set a basic behaviour in the initialiser that logs when it is triggered and sets the assignee to the logged in user. 
        import com.atlassian.jira.component.ComponentAccessor 
        
        def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser() 
        getFieldById("assignee").setFormValue(user.name) 
        
      2. Set a basic behaviour on the assignee field as server-side script that logs when triggered and sets an error if the assignee field value is -1 or null.
        def relatedField = getFieldById(getFieldChanged())
        def value = relatedField.getValue()
        
        log.error("""
           value = $value                    
           value null = ${! value}
           value -1 = ${value == "-1"}          
        """)
        if( ! value || value == "-1" ){ relatedField.setError("Cannot be unassigned")
        }else{
          relatedField.clearError()
        } 
        
      3. Save and map to your project.
      4. Open the create/edit window and you should see in the logs that the assignee field script runs without any interaction with it and sets an error on the assignee field (edit: for a split second, then it gets removed)

      Reproduction video: 

      https://drive.google.com/file/d/1H_I8xZ59pwjPKbmujV0wArGe5pYBx2u5/view

       

      Edit:

       Also it behaves differently for like description field.

      1. Set a basic behaviour in the initialiser that logs when it is triggered and sets the description field any value

      import com.atlassian.jira.component.ComponentAccessor
      def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
      getFieldById("description").setFormValue("Random text blah blah blah")
      

      2. Set a basic behaviour on the description field as server-side script that logs when triggered and sets an error if the description field value is -1 or null.

      def relatedField = getFieldById(getFieldChanged())
      def value = relatedField.getValue()
      log.error("""
         value = $value                   
      value null = ${! value}
         value -1 = ${value == "-1"}          
      """)
      if( ! value || value == "-1" ){ 
        relatedField.setError("Cannot be unassigned")
      }else{
      relatedField.clearError()
      }
      

      3. Save and map to your project.

      4. Open the create/edit window and you should see in the logs that the description field script runs without any interaction with it and sets an error on the description field (error message doesn't disappear like in assignee example)

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jechlin Jamie Echlin
              Reporter:
              mclark Matthew Clark
              Votes:
              9 Vote for this issue
              Watchers:
              30 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: