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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

202 views 1 18
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