Hello!
I found this script that puts random assignee for issues. https://library.adaptavist.com/entity/round-robin-assign
Brut I need this script to work only on specific Customer request types, not on all issues that are created -
So precondition would be -
if Customer request type is Type1, Type2 or Type 3,
it runs and puts random assignee (chosen from project role) for issue
Otherwise it uses default assignee (set in request form).
I would really appreciate if someone can help me with this precondition.
Hi @Santa Aga , welcome to the Community Forums!
While I can't help with specifics, I did some research and ScripRunner does have conditions. Both built-in and custom.
Check out these two resources:
https://docs.adaptavist.com/sr4js/latest/features/workflows/conditions
Hi! Thank you!
I have been playing around with the script and also asked chatGPT.
1. Script is used for Create step
2. There is already set assignee for each customer request type by default when creating an issue
3. Script logic meets requirements:
- If Customer Request Type is Type1, it should proceeds with the reassignment logic. It finds the latest created issue with the same request type,
-sets the default assignee to null, and then assigns the issue to the next user in the round-robin sequence.
- else says that it does not allow to change the assignee.
4. The script works without errors, but it still does not changes the original assignee to the one with RoundRobin role
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.servicedesk.api.requesttype.RequestType
import groovy.transform.Field
def cfRequestType = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10702")
def requestType = issue.getCustomFieldValue(cfRequestType)
def issueManager = ComponentAccessor.issueManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
if (requestType == "Type1"){
// The role you want assignees to set from
final roleName = 'RoundRobin'
// If it is true, the assigned issues will be reassigned
final reassignedIssues = true
// 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 }
// There are no users in the specific project role
if (!users) {
log.info ("No users for project role $roleName")
return
}
if (reassignedIssues) {
// Find the latest created issue id that has an assignee
def lastIssueIdWithAssignee = issueManager.getIssueIdsForProject(issue.projectObject.id)
.findAll { foundIssueId ->
def foundIssue = issueManager.getIssueObject(foundIssueId)
foundIssue.requestType.name == "Type1"
}
.max()
if (!lastIssueIdWithAssignee) {
// Set the original assignee to null before reassigning
issue.setAssigneeId(null)
issue.setAssignee(users.first())
return
}
// Set the original assignee to null before reassigning
issue.setAssigneeId(null)
def lastAssignee = issueManager.getIssueObject(lastIssueIdWithAssignee).assignee
def lastAssigneeIndex = users.indexOf(lastAssignee)
def nextAssignee = users[(lastAssigneeIndex + 1) % users.size()]
issue.setAssignee(nextAssignee)
}
} else {
log.info('Reassignment not allowed, or the issue is already assigned')
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.