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?
Community moderators have prevented the ability to post new answers.
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();
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-
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.