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