Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I receive NULL for oldstring for Fix Version on my listener and not the old fix version

Jeremy Schrek
Contributor
March 22, 2021

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

 

1 answer

1 accepted

0 votes
Answer accepted
Derek Fields (RightStar)
Community Champion
March 22, 2021

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.

Jeremy Schrek
Contributor
March 22, 2021
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)

 

Suggest an answer

Log in or Sign up to answer