Groovy script to track issue status changes in listener

Vineela Durbha June 2, 2021

Hi team,

 

I am looking for the groovy script to track the changes of status of an issue. I want to trigger some actions if at all the issue status has been changed. 

Can someone please help on the script to track this change?

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 2, 2021

A listener for this would need to be configured to trap and react to any event fired by your transistions, which might be a bit of a manual slog to work out all of them, but the alternative of putting a post-function into every transition is much worse.  In fact, I'd just listen for most events and then check "has status changed in this event"

You've not really said what you want to do with "track this change", but here's a pile of sample listeners for SR that might help you with some of it - https://library.adaptavist.com/search?term=listener

Vineela Durbha June 2, 2021

Hi @Nic Brough -Adaptavist- 

Thanks for your reply.

I am writing this listener , whenever status of an issue is changed , I want to push some values to database.  

I am trying to do this with 'changeItem' and so looking for a help on the script line for the status change to be tracked.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 2, 2021

Ok, I want to suggest a slightly different approach on a couple of points.

First, an event contains a whole load of information about the action that triggered it, and that's directly available to your listener code, so there's a good chance that you don't need to start messing with reading issues for data you already have in the event.

Second, you mention changeitem, which is the name of a table in a jira database.  In a listener, you have direct access to the api, which is a far better way to fetch Jira data than reading the database for raw data.  Reading a Jira database is the worst possible way to get data out of a Jira system.  

Now, bearing in mind the sequence of things that happen when you're talking about listeners, the bit we're interested in is:

  1. User says "yes, confirm this transition" (and it passes validation)
  2. Jira executes post-functions
  3. An event is fired
  4. Your listener sees an event and runs code because it saw one it should run for.  Almost all listeners use data in the event to process what they do

One thing that springs out here is that all the data that is going to go into the changeitem table is also in the event.  As well as the rest of the change information that's held in other tables in the database. 

So, use the event data in your code, forget the Jira database.

You say you want to "push some values to a database" - that's fine, but what values and what database?

Suggest an answer

Log in or Sign up to answer