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

Changing issue priority through a listener on issue update

Steven Mustari
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.
May 10, 2016

I have the following code that is working as a post function to update issue priority based on a custom field. I am trying to make this process dynamic and occur whenever the issue is updated. This is what I have so far:

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
 
log.info("[UpdateParentPriority] Script fired");

MutableIssue mutableIssue = (MutableIssue) issue;
ComponentManager componentManager = ComponentManager.getInstance();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject("customfield_11608");     // 11608 = Category Priority

def customFieldValue = getCustomFieldValue(customField);

switch (customFieldValue) {
    case "2":
        mutableIssue.setPriorityId("10000");    // 2 = Trivial
        log.info("[UpdateParentPriority] Priority 2 set to Trivial");
        break;
    case "3":
        mutableIssue.setPriorityId("10001");    // 3 = Lowest
        log.info("[UpdateParentPriority] Priority 3 set to Lowest");
        break;
    case "4":
        mutableIssue.setPriorityId("10002");    // 4 = Low
        log.info("[UpdateParentPriority] Priority 4 set to Low");
        break;
    case "6":
        mutableIssue.setPriorityId("10003");    // 6 = Medium
        log.info("[UpdateParentPriority] Priority 6 set to Medium");
        break;
    case "8":
        mutableIssue.setPriorityId("10004");    // 8 = High
        log.info("[UpdateParentPriority] Priority 8 set to High");
        break;
    case "9":
        mutableIssue.setPriorityId("10005");    // 9 = Highest
        log.info("[UpdateParentPriority] Priority 9 set to Highest");
        break;
    case "12":
        mutableIssue.setPriorityId("10006");    // 12 = Critical
        log.info("[UpdateParentPriority] Priority 12 set to Critical");
        break;
    default:
        log.info("[UpdateParentPriority] ERROR - unable to set issue priority");
        break;
}

// Update Issue
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getUserUtil().getUserObject('automation'), mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false);

 

When I run this code as a listener I get an error:

 

2016-05-10 18:37:51,586 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [Category Priority]
	at Script237.run(Script237.groovy:16)

 

The scripted field being called is an SIL Scripted field that is being calculated.. Is this the reason I am throwing this error?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Steven Mustari
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.
May 11, 2016

I think my issue was that since this is a listener, there is no value assigned to "issue" by default. I added the following and it seems to have resolved it:

 

def issue = event.getIssue();
0 votes
Ashraful Hasan [Adaptavist] May 10, 2016

Hi

try "issue.getCustomFieldValue(customField);

getCustomFieldValue is a method of Issue  Interface: https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/Issue.html#getCustomFieldValue-com.atlassian.jira.issue.fields.CustomField-

TAGS
AUG Leaders

Atlassian Community Events