Remote CustomFields changes to local comment

Originally asked by Daniel on 15 April 2021 (original question)


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   
	}
}

Answer by Daniel on 16 April 2021

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.


Comments:

Francis Martens (Exalate) commented on 18 April 2021

Nice! good find.

Answer by Francis Martens (Exalate) on 15 April 2021

Daniel

Try to compare the values

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

Comments:

Daniel commented on 16 April 2021

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.

Francis Martens (Exalate) commented on 16 April 2021

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

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.