I need to edit the script below to set the issue assignee according to a project role list randomly.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType
import com.atlassian.jira.issue.CustomFieldManager;
import org.apache.log4j.Category
log.setLevel(org.apache.log4j.Level.DEBUG)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def field = customFieldManager.getCustomFieldObject("customfield_10115")
Object cfVal = issue.getCustomFieldValue(field)
HashMap<String, Option> hashMapEntries = (HashMap<String, Option>) cfVal
if (hashMapEntries != null) {
Option parent = hashMapEntries.get(CascadingSelectCFType.PARENT_KEY)
Option child = hashMapEntries.get(CascadingSelectCFType.CHILD_KEY)
def first = parent.toString()
def second = child.toString()
//-----------------------------------------------------------------------------------------------------------
if (second == "ACM"){
// The role you want assignees to set from
final roleName = 'SAPN1 - ACM'
final reassignedIssues = true
def issueManager = ComponentAccessor.issueManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
// Get all of the users associated with the specified project role
def projectRole = projectRoleManager.getProjectRole(roleName)
// Sort the users of the project role using the user key
def users = projectRoleManager.getProjectRoleActors(projectRole, issue.projectObject).applicationUsers.toSorted { it.key }
log.debug("Users: " + users);
issue.setAssignee(users.first()) //Set the first user as assignee
}}
In the last line of this script the issue assignee is changed to project role "SAPN1 - ACM" first member, but I need to change the script to get a random user in this project role.
I tried to modify the last line as below but it did not work.
issue.setAssignee(users.random()) //Set the first user as assignee
Can someone help me with this script?