2
1
0

Is it there a way to generate a local comment containing the value of a custom field every time this custom field is updated and do nothing when the custom field value was the same, in order to prevent to generate a duplicated comment every time any other field if synched.

I tried the following code, but it doesnt work, I got the duplicated comment in all syncs.


if (replica.customFields."Steps to Reproduce") {  
	if (!replica.customFields."Steps to Reproduce".equals(previous?."Steps to Reproduce")){    
	//Create Comment with content of ""Steps to Reproduce""    
	String stepsToReproduce = replica.customFields."Steps to Reproduce".value
	issue.comments = commentHelper.addComment(stepsToReproduce, issue.comments)  
	}
  	else
  	{  
		// do nothing   
	}
}
    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      Francis Martens (Exalate) I´ve managed to make it work. I replace equals() with == operator and after that conditions become true or false depending on current is equals or not to previous.


      From what I research, It seems there it is already known that Groovy´s x.equal().y not always returns TRUE ifs x == y 


      The working code looks like that (I have to add some lines to consider the first sync:




      if (replica.customFields."Steps to Reproduce") { 
          if(!firstSync){
              previousSteps = previous?.customFields."Steps to Reproduce"?.value
              currentSteps = replica.customFields."Steps to Reproduce"?.value
              if (previousSteps != currentSteps){ 
                  String stepsToReproduce = replica.customFields."Steps to Reproduce".value
      	        issue.comments = commentHelper.addComment(stepsToReproduce, issue.comments)  
      	    }
        	    else
        	    {  
      		// do nothing   
      	    }
          }
      	else {
      	        String stepsToReproduce = replica.customFields."Steps to Reproduce".value
      	        issue.comments = commentHelper.addComment(stepsToReproduce, issue.comments) 
      	}
      }
      
      


      Thank you very much for  your help.

      CommentAdd your comment...
    2.  
      1
      0
      -1

      Daniel


      Try to compare the values

      if (!replica.customFields."Steps to Reproduce"?.value?.equals(previous?."Steps to Reproduce".value)


      	
      1. Daniel

        Francis Martens (Exalate) thanks for your answer. I tested using values but unfortunately I get the same results.

        It looks as the comparison:


        replica.customFields."Steps to Reproduce"?.value?.equals(previous?."Steps to Reproduce".value

        is always false


        I think this is because the previous value of the custom field is not stored or something like that.


        I need to find a condition detecting when the value of the custom field (test) was updated.


        The custom field only exist in one side, in the other side, I just need to post a comment every time the field is updated.





      2. Francis Martens (Exalate)

        The previous will only be available after the first sync.
        Can you check what the values are by adding 


        debug.error("current = '${replica.customFields."Steps to Reproduce"?.value}', previous = ${previous?.customFields."Steps to Reproduce"?.value})


        When a new incoming message is processed, an error will be generated containing the details allowing you to understand what is going on

      CommentAdd your comment...