Set Issue Priority in Jira Ticket

Hemanshu January 9, 2017

Hi,

I want to set issue priority in JIRA Ticket using groovy. We have a drop down list in JIRA ticket which is populated with a default priority once an issue is created. e.g "Priority 6".

With the help of groovvy I want to set the priority as "Priority 4".

I am able to get the issue priority  using the following code, but not able to set a new priority:

 

def priority=issue.priorityObject.name;

 

for setting:

 

issue.setPriority(new priority);

 

giving below error:

 

No signature of method: com.atlassian.jira.issue.IssueImpl.setPriority() is applicable fo
r argument types: (java.lang.String) values: [ Priority 4]
Possible solutions: setPriority(org.ofbiz.core.entity.GenericValue), getPriority(), setPriorityId(java.lang.String)
at Script480.run(Script480.groovy:66)

 

 

Pls suggest

 

 

2 answers

1 accepted

2 votes
Answer accepted
Thanos Batagiannis _Adaptavist_
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.
January 9, 2017

Hi Hemanshu,

Try something like 

def priority4 = "Priority 4"
def priorityToSetId = ComponentAccessor.getConstantsManager().getPriorityObjects().find {it.name == priority4}?.getId()

if (! priorityToSetId)
    log.debug "Could not find priority with name: $priority4"

issue.setPriorityId(priorityToSetId)

regards, Thanos

0 votes
Hemanshu January 10, 2017

Hi Thanos, still not working:

This is my code:

def mail_priority=descArr[19].substring(9);//this is fetching string from a line. The string in this case is "Priority 4"

def final_priority=mail_priority.toString();//converting to String

def priorityToSetId = ComponentAccessor.getConstantsManager().getPriorityObjects().find {it.name == final_priority}?.getId();

if (! priorityToSetId)
log.debug "Could not find priority with name: $final_priority"

log.debug("Setting Priority");
issue.setPriorityId(final_priority);

 

 

pls suggest

Thanos Batagiannis _Adaptavist_
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.
January 10, 2017

I suppose this is a post function and is before the store issue step right ?

Also do you get any errors ? What about the debug messages in your logs ?

JIRA and SR versions ?

Hemanshu January 10, 2017

Hi Thanos,

 

This is part of a script which parses the content of an incoming email in JIRA to field values in Jira.

Hence this code is a post function which is part of transition:

*-------> Tier 1 New

this code:

def mail_priority=descArr[19].substring(9);//this is fetching string from a line. The string in this case is "Priority 4"

def final_priority=mail_priority.toString();//converting to String

def priorityToSetId = ComponentAccessor.getConstantsManager().getPriorityObjects().find {it.name == final_priority}?.getId();

if (! priorityToSetId)
log.debug "Could not find priority with name: $final_priority"

log.debug("Setting Priority");
issue.setPriorityId(final_priority);

 

 

is fecthing priority from the email(as Priority 4) and parsing the same with the "Priority" field in JIRA whose default value is set up as "Priority 6".

I cannot find any error in logs, but now after ticket creation, the priority field disappears.

Hence, there is no value set for "Priority" field in JIRA during ticket creation.

Suggest an answer

Log in or Sign up to answer