Script Runner groovy script help

Travis Alexander [Empyra] January 29, 2019

I'm just going to throw this out there.. 

Can anyone write me a (or copy paste a similar) groovy script that I can use as a post function that will auto-assign the issue based on conditions?

A single post function will need a script with the following logic:

 

IF Custom Field = "A" AND Issue Type = Story THEN set assignee to 'talexander'

IF Custom Field = "B" AND Issue Type = Story THEN set assignee to 'tsmith'

IF Custom Field = "A" AND Issue Type = Task THEN set assignee to 'bjones'

etc.. 

Jira 7.10.X

Thanks in advance!

1 answer

0 votes
Alvin
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.
January 29, 2019

Maybe this could help. try to change instead of custom field value, get the issuetype

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.getIssueManager();
def userManager = ComponentAccessor.getUserManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cField = customFieldManager.getCustomFieldObject("customfield_12400");
def cFieldValue = issue.getCustomFieldValue(cField);

if (cFieldValue.toString() == "Security") {
def assignee = userManager.getUserByKey("i849194");
issue.setAssignee(assignee);
}
else if (cFieldValue.toString() == "Operations") {
def assignee = userManager.getUserByKey("i826121");
issue.setAssignee(assignee);
}

else if (cFieldValue.toString() == "Instance Creations/Backups") {
def assignee = userManager.getUserByKey("i825046");
issue.setAssignee(assignee);
}

Suggest an answer

Log in or Sign up to answer