Hi,
I'm trying to implement some automation on a transition in a workflow. In the transition, I would like for the Issue to be reassigned if the value in a custom field (User Picker (single user)) exists in a specific User Group.
In 'plain English' the script would be something like this:
if (Ticket Owner value exists in "User Group A") {
Assignee = "Specific User A";
} else if (Ticket Owner value exists in "User Group B") {
Assignee = "Specific User B";
}
I'm currently using the Precondition: User Is In Any Groups (JSU) post function, which kinda does what I want, only I don't want it checking against the current user executing the transition; this will cause problems in our work processes in the future.
I believe Script Runner can be used to achieve what I want. I've been trying to use the examples on this page but I haven't been able to achieve much.
Hi @Stuart_Hart
In the scriptrunner world, you will be looking at a custom post function, not behaviors/conditions.
They have many built-in functions, but none that does exactly what you want. So you'll need to create it from scratch.
Something like this may work for most cases:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def crowdService = ComponentAccessor.crowdService
def userManager = ComponentAccessor.userManager
def groupMapping = [
'User Group A': 'username of specific user a',
'User Group B': 'username of specific user B',
]
def ownerCfs = customFieldManager.getCustomFieldObjectsByName('Ticket Owner')
if(!ownerCfs) return null //collection is empty, the custom field doesn't exist with that name
def owner = issue.getCustomFieldValue(ownerCf.first())
if(owner && owner.active){
groupMapping.find{ group, assigneeUsername ->
if(crowdService.isUserMemberOfGroup(owner.name, group)){
def assignee = userManager.getUserByName(assigneeUsername)
issueInputParameters.setAssigneeId(assignee.Id.toString() )
return true
}
}
} else {
// perhaps you have a default assignee when the ticket owner doesn't exist or is inactive?
}
Rather than a simple if then else, I created a map of group:username.
This way, you can expand your cases without having to expand the logical portion of the script. The first group with the ticket owner will be found and the corresponding user assigned.
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.