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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

727 views 6 13
Read article

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