Script Runner: setassignee + setSecurityLevelId if Member in Group

Can u help me with my task? I need check assignee user group, and If it match to some group, set securitylevel and set(update) assignee to Team Leader.

But it doesn't work ;(

Security Level Set = ok

SetAssisgnee = not

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.jira.user.util.DefaultUserManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User

GroupManager groupManager = ComponentManager.getComponentInstanceOfType(GroupManager.class);

UserManager userManager = UserManager.getInstance();
User usera = ComponentManager.getInstance().getUserUtil().getUser('username');
User userb = ComponentManager.getInstance().getUserUtil().getUser('username');
User userc = ComponentManager.getInstance().getUserUtil().getUser('username');
User userd = ComponentManager.getInstance().getUserUtil().getUser('username');
User usere = ComponentManager.getInstance().getUserUtil().getUser('username');
User userf = ComponentManager.getInstance().getUserUtil().getUser('username');
  
//String reporter_usr = issue.getReporterId() 
 
	if ( groupManager.isUserInGroup(issue.getAssigneeId(), "IT")) {issue.setSecurityLevelId(10102); issue.setAssignee('usera');}
	else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "SEO")) {issue.setSecurityLevelId(10103); issue.setAssignee('userb');}
	else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "Marketing")) {issue.setSecurityLevelId(10104); issue.setAssignee('userc');}
	else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "Design")) {issue.setSecurityLevelId(10107); issue.setAssignee('userd');}
	else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "CityFrog")) {issue.setSecurityLevelId(10101); issue.setAssignee('usere');}
	else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "Office")) {issue.setSecurityLevelId(10100); issue.setAssignee('userf');}

3 answers

Fixed!

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
	
GroupManager groupManager = ComponentManager.getComponentInstanceOfType(GroupManager.class)
userUtil = ComponentManager.getInstance().getUserUtil()

  
//String reporter_usr = issue.getReporterId() 
 
	if ( groupManager.isUserInGroup(issue.getAssigneeId(), "IT")) {issue.setSecurityLevelId(10102); issue.setAssignee(userUtil.getUserObject("username"));}
	else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "SEO")) {issue.setSecurityLevelId(10103); issue.setAssignee(userUtil.getUserObject("username"));}
else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "Marketing")) {issue.setSecurityLevelId(10110); issue.setAssignee(userUtil.getUserObject("username"));}
else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "Design")) {issue.setSecurityLevelId(10111); issue.setAssignee(userUtil.getUserObject("username"));}
else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "CityFrog")) {issue.setSecurityLevelId(10112); issue.setAssignee(userUtil.getUserObject("username"));}
else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "Office")) {issue.setSecurityLevelId(10114); issue.setAssignee(userUtil.getUserObject("username"));}
else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "Managers")) {issue.setSecurityLevelId(10109);} else if ( groupManager.isUserInGroup(issue.getAssigneeId(), "Support")) {issue.setSecurityLevelId(10113);}


new feature, i need fix my scrit.
cuz if reporter group are same like assigneeuser - do only security level

done again.
if (groupManager.isUserInGroup(issue.getReporterId(), "IT") == groupManager.isUserInGroup(issue.getAssigneeId(), "IT")) {issue.setSecurityLevelId(10102);}

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

465 views 7 5
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