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 :-(
Community moderators have prevented the ability to post new answers.
ID will be a number not a string . Try
myIssue.setPriorityId(1)
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Additionally to Mizans answer be aware that you put your postfunction before the "Create the issue originally" post function to have an effect.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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").
By the way - can I place this script as a validator for 'Resolve' transition just for debugging purposes?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have to submit a String of the ID.
myIssue.setPriorityId("5")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.