I am writing a listener in groovy that checks the Fix Version on Issue Updated Event but I get NULL for oldstring when I call it from the code.
Here is a snip of the code.
change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Fix Version"}
log.warn(change)
//log.warn("all changes : "+ event?.getChangeLog()?.getRelated("ChildChangeItem"))
log.warn("--------Vairables created")
if(change)
{
log.warn("old string is " + change.oldstring)
log.warn("new string is " + change.newstring)
if(change.oldstring == ver || change.newstring == ver)
{
if(change.oldstring == ver)
{
subject = "An item was added to " + ver
body = "Ticket " + issue.getId() + " was added to " + ver
}
if(change.newstring == ver)
{
subject = "An item was removed from " + ver
body = "Ticket " + issue.getId() + " was removed to " + ver
}
When testing this I am selecting edit on the ticket. Removing the old fix version and adding a new fix version. The old one is always NULL.
Using v8.13.2
What is happening is that there are two events occurring. One event removes the old value. The other event adds the new value. So, when the new value is being added, the "oldvalue" is null.
Try something like this (I haven't tested it):
def changes = event?.getChangeLog()?.getRelated("ChildChangeItem")?.findAll {it.field == "Fix Version"}
log.warn(change)
//log.warn("all changes : "+ event?.getChangeLog()?.getRelated("ChildChangeItem"))
log.warn("--------Vairables created")
changes.each ( change ->
{
log.warn("old string is " + change.oldstring)
log.warn("new string is " + change.newstring)
if(change.oldstring == ver || change.newstring == ver)
{
if(change.oldstring == ver)
{
subject = "An item was added to " + ver
body = "Ticket " + issue.getId() + " was added to " + ver
}
if(change.newstring == ver)
{
subject = "An item was removed from " + ver
body = "Ticket " + issue.getId() + " was removed to " + ver
}
}.
This should give you the two messages that you are looking for.
old string is [null, 2.3]
new string is [2.4, null]
I am now getting the data by using findAll but I am not entering the if even though
def ver = "2.4"
if(change.oldstring == ver || change.newstring == ver)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.