Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

0 votes
Derek Fields Community Leader Mar 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.

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you