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

Jenin CM February 25, 2014

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 votes
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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.

Jenin CM February 25, 2014

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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