The scenario is we create an issue in a project, it gets auto-assigned using the Component settings. Later, we need to move the issue to another project and another Component, but the auto-assignment does not trigger. I also tried with issues that were 'unassigned' but the Component auto-assignment still doesn't trigger on move. But that's not my problem--I've accepted the behavior and moved on =)
What I want to know if there is a way I can trigger the behavior via a script. I'm currently working on a Listener in Scriptrunner but I'd rather not recreate the behavior from scratch (are assignments being made by project default, component lead, some other criteria). Is there a function in the Java API that I can call to cause the assignee to be re-evaluated? I know it's a stretch, but I thought I would check before I did too much more work.
Okay, I figured it out...if you pass in a -1 for the 'name' value when using the REST API, it is like setting the assignee to Automatic in the UI and will process the assignment rules. I ran this in the Script Console so there is additional code to grab a test issue, but just remove that and uncomment the line that gets the issue from the event:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import com.atlassian.jira.component.ComponentAccessor;
// Remove these lines and uncomment the line below when using in a listener
def issueManager = ComponentAccessor.getIssueManager();
def eventIssue = issueManager.getIssueObject('SB-347');
def components = eventIssue.getComponents();
//def eventIssue = event.getIssue();
def assignee = eventIssue.assignee;
def issueKey = eventIssue.key;
def baseURL = ComponentAccessor.getApplicationProperties().getString("jira.baseurl");
log.debug("Processing auto-assignment for moved issue: " + issueKey);
log.debug("Assignee = " + assignee);
if(!assignee) {
log.debug("Updating issue for auto-assignment");
def http = new HTTPBuilder("${baseURL}/rest/api/2/issue/${issueKey}/assignee")
def authString = 'service:*********'.getBytes().encodeBase64().toString();
http.request(PUT, ContentType.JSON) {
requestContentType = ContentType.JSON;
request.addHeader("authorization: Basic ${authString}", "ContentType: application/json");
body = [ name: -1 ];
response.success = { resp, JSON ->
log.debug(resp.statusLine);
log.debug("Successful = " + JSON)
};
response.failure = { resp, JSON ->
log.warn(resp.statusLine);
log.warn("Failed to assign issue to automatic assignment = " + JSON)
};
};
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.