Changing issue priority through a listener on issue update

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"[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"[UpdateParentPriority] Priority 2 set to Trivial");
    case "3":
        mutableIssue.setPriorityId("10001");    // 3 = Lowest"[UpdateParentPriority] Priority 3 set to Lowest");
    case "4":
        mutableIssue.setPriorityId("10002");    // 4 = Low"[UpdateParentPriority] Priority 4 set to Low");
    case "6":
        mutableIssue.setPriorityId("10003");    // 6 = Medium"[UpdateParentPriority] Priority 6 set to Medium");
    case "8":
        mutableIssue.setPriorityId("10004");    // 8 = High"[UpdateParentPriority] Priority 8 set to High");
    case "9":
        mutableIssue.setPriorityId("10005");    // 9 = Highest"[UpdateParentPriority] Priority 9 set to Highest");
    case "12":
        mutableIssue.setPriorityId("10006");    // 12 = Critical"[UpdateParentPriority] Priority 12 set to Critical");
    default:"[UpdateParentPriority] ERROR - unable to set issue priority");

// 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]


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

1 vote
Answer accepted

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();

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Friday in United States

Confluence Security Advisory

Good morning Members, Not sure if you are aware. Please read the following: More details: https://co...

43 views 1 0
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you