Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Need a script (groovy) to change issue's priority

e October 21, 2013

Hello! I need a script on groovy which will set the issue's priority to Critical. I am going to add the script as a post-function. Help me, please.

This is my attempt:

MutableIssue myIssue = issue

myIssue.setPriorityId("Blocker")

is does not work :-(

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Mizan
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.
October 21, 2013

ID will be a number not a string . Try

myIssue.setPriorityId(1)

JamieA
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.
October 22, 2013

This is wrong, it is a string, it should be "1"

Sorry for the downvote but I wanted a more correct answer to be top!

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.
October 22, 2013

You have to read the cf value from the existing issue object. So instead of val = pr.getValue(issue) you should use issue.getCustomFieldValue(pr).getValue() to get the String of the selected option.

e October 22, 2013

Thank a lot. This one worked! Thank you so much.

NorskK May 28, 2015

Hi. Could you post the entire script you got working (if you still have it). I'm trying more or less the same but have som issues geting it right

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.
October 21, 2013

Additionally to Mizans answer be aware that you put your postfunction before the "Create the issue originally" post function to have an effect.

e October 21, 2013

Thanks! Now I have changed the code to what Mizan suggested and

1) I get if I run the code as a validator "An unknown exception occured executing Validator com.onresolve.jira.groovy.GroovyValidator@6a62521f: root cause: java.lang.NullPointerException"

2) My issue's priority does not change if I run it as a post-function (before "Create Issue originally").

Henning Tietgens

By the way - can I place this script as a validator for 'Resolve' transition just for debugging purposes?


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.
October 21, 2013

I don't think so. Maybe the issue object within the validator is not a mutable issue and therefor you get the NPE. A validator is only to check, not to modify the issue.

Is the suggested ID from Mizan (1) a valid ID? Try to edit a priority as admin to see the ID of the priority in the link.

e October 21, 2013

Henning Tietgens

So, what I've just figured out is that 'Trivial' == 5. So, I create an issue, set it's priority as 'Blocker' on the screen, then I

I tried to use my post-function with code:

import com.atlassian.jira.issue.MutableIssue;

MutableIssue myIssue = issue

myIssue.setPriorityId(5)

but in vain! What I expected was that Blocker turns into Trivial.

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.
October 21, 2013

You have to submit a String of the ID.

myIssue.setPriorityId("5")

Like Anna Kapitonova likes this
e October 21, 2013

That's it! Thanks a lot!

Like Anna Kapitonova likes this
e October 21, 2013

Can I take a value from a custom field in my post-function, and by looking at it - decide issue's priority?

I guess the custom field that determines the priority of the issue is not available at the stage of post-function.

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.
October 21, 2013

Try

cfValues['name of customfield']

to get the customfield value. If it's a cf with predefined options (single select) you have to use

cfValues['name of customfield'].getValue()

to get the string value.

e October 22, 2013

I'm afraid I am using a separate script, like /data/groovy/script.groovy, I supposed cfValues[] - is not available here.

It's a CF with predifined options.

When I use the script as validator, I successfully can get values like this:

CustomFieldManager prod_manager = ComponentManager.getInstance().getCustomFieldManager();

CustomField pr = prod_manager.getCustomFieldObject('customfield_14538')

def val = pr.getValue(issue)

When I use the script as a post-function, I can't get values, nor can I throw an exception: invalidInputException = new InvalidInputException("exception text")

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events