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

1 vote
Accepted answer

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 13 hours ago in Agile

What is Scrum? A good, bad, and ugly answer.

In a world of dark-scrum, faux-scrum, and scrum-butt, the question still remains: What is scrum and how do you do it “right?” That’s the question we set out to answer. I'm Max, I've been teaching c...

56 views 0 1
Join discussion

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