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

This widget could not be displayed.

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);}


This widget could not be displayed.

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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

553 views 25 15
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