# Remote CustomFields changes to local comment

**URL:** <https://community.exalate.com/t/remote-customfields-changes-to-local-comment/4675>\
**Category:** General Questions\
**Tags:** comments, customfields, migrated\_question\
**Created:** [November 4, 2024, 7:15am UTC](https://community.exalate.com/t/remote-customfields-changes-to-local-comment/4675 "2024-11-04T07:15:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:15am UTC](https://community.exalate.com/t/remote-customfields-changes-to-local-comment/4675/1 "2024-11-04T07:15:32Z")

</div>

_Originally asked by Daniel on 15 April 2021 [(original question)](https://oldcommunity.exalate.com/questions/25071375)_

* * *

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.

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

```

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:15am UTC](https://community.exalate.com/t/remote-customfields-changes-to-local-comment/4675/2 "2024-11-04T07:15:33Z")

</div>

_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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:15am UTC](https://community.exalate.com/t/remote-customfields-changes-to-local-comment/4675/3 "2024-11-04T07:15:40Z")

</div>

_Answer by Francis Martens (Exalate) on 15 April 2021_

Daniel

Try to compare the values

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

```

```auto
	

```

* * *

#### 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:
> 
> ```auto
> 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
> 
> ```auto
> 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

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 6, 2024, 7:16am UTC](https://community.exalate.com/t/remote-customfields-changes-to-local-comment/4675/4 "2024-11-06T07:16:28Z")

</div>

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