Groovy script to add/remove watchers on the basis of Priority

Hi,

I need a groovy script for the below situation:

1. Without having to do a workflow transition, if the ticket is edited and the priority is moved up (After it is vetted) to critical or serious…add the appropriate critical or serious user to watcher

2. If an issue us lowered from critical to serious…remove the critical user as watch and add the serious user

3. If an issue is lowered from either critical or serious to Important or minor…remove the critical or serious user from watcher
I need the script as i am not well versed with the groovy scripting.
Regards,
Jenin

1 answer

0 vote
Henning Tietgens Community Champion Feb 25, 2014

I'm sorry but I think it's not a good idea to use such scripts without any knowledge in scripting JIRA. You have to maintain all of your scripts if something goes wrong or if you want to update JIRA.

In your case you should implement a listener which looks for changes to the priority field and than adapt the watchers accordingly. Look into the documentation of Script Runner on how to write a listener, look into the JIRA API on how to read issue fields and add/remove watchers.

how can I check if priority has been moved from critical to serious. I mean i can check for priority of an issue

if((priority.equals("2")) || (priority.equals("1"){

//Assign to watchers who need for showstopper

//watchUsers(CRITICAL_users);

watchUsers(CRITICAL_test);

}

I am not able to figure out on how could I check if the priority has been changed from Critical to Serious.

Henning Tietgens Community Champion Feb 26, 2014

You can get the old values from the changelog like this.

event?.changeLog?.getRelated('ChildChangeItem')?.findAll{ it.field=='priority' }?.each {
    previousPriority = it.oldvalue
    // ...
}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

91 views 0 1
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you