Update custom filed

Originally asked by sapir monza on 27 April 2021 (original question)


Hi,

I have the following code in order to sync fixVersions filed with customer “Fix in versions” filed:
issue.customFields.“Fix in version”.value = replica.fixVersions?.collect

{it.name}.join(“,”)

It works fine!
But, I want this code will run only when fixVersions filed is updated and not every time.
I tried something like:

if (replica.fixVersions.updated?){
issue.customFields.“Fix in version”.value = replica.fixVersions?.collect{it.name}

.join(“,”)
}

It doesn’t work, I guess my “if” condition syntex is not right.
What do I need to put in the condition?

Thanks!
Sapir


Answer by Daniel on 27 April 2021

you can try by comparing with previous fixVersions

previousFixVersions = previous?.fixVersions
currentFixVersions = replica?.fixVersions
        if (previousFixVersions != currentFixVersions){ 

//your code here

}

or

if (!replica?.fixVersions?.equals(previous?.fixVersions){  
//your code here  
}  
  
Nota: there is a known issue in Groovy causing that x.equal.y sometimes is not the same as x == y. The first option always worked for me.  
  


Answer by sapir monza on 29 April 2021

Awesome!
The first works like a cream, thanks a lot! :smile:


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