The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Approvals by User Group

Derek Sheeman
Contributor
May 11, 2017

I am looking for a way to present a list of User Groups to customers seeking approval for their various team and then to have JIRA Service Desk populate the approvers field with the members of that user group at the time of issue creation.

I cannot find a way to do this in JIRA by default.

Presenting a list of ALL users in the user cache is unacceptable (multi-user picker).

We are not interested in the Herzum plugin.

Has anyone done this with Script Runner?

Tapping user groups really feels like it should be a viable choice for Jira Service Desk approvers out of the box.

2 answers

2 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

3 votes
Answer accepted
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
May 15, 2017

Unfortunately, Group Pickers can't be added to the screen of a Service Desk portal, so there's no easy way to present users with a list of groups to pick from. See (and comment/vote) https://jira.atlassian.com/browse/JSDSERVER-86.

That said, as a work around, you could setup a single select list custom field that had a list of group names that you wanted to be valid as approval groups, then use ScriptRunner to populate the Approvers field on the Create transition.

Something like

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder

def groupManager = ComponentAccessor.groupManager

def customFieldManager = ComponentAccessor.customFieldManager
def groupNameField = customFieldManager.getCustomFieldObjectByName("SelectListA")
def groupNameSelected = issue.getCustomFieldValue(groupNameField)

def group = groupManager.getGroup(groupNameSelected.toString())
def users = groupManager.getDirectUsersInGroup(group)

def approversField = customFieldManager.getCustomFieldObjectByName("Approvers")
log.debug("Approvers: ${issue.getCustomFieldValue(approversField)}")

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
approversField.updateValue(null, issue, new ModifiedValue("", users), changeHolder);

You'd need to setup the approval workflow as normal.

Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
May 15, 2017

You can keep your select list in sync with your groups via a script like this one running as a listener or a service:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.GlobalIssueContext

def customFieldManager = ComponentAccessor.customFieldManager
def groupNameField = customFieldManager.getCustomFieldObjectByName("Approval Group Name")
def optionsManager = ComponentAccessor.optionsManager
def groupManager = ComponentAccessor.groupManager
groupManager.getAllGroups().eachWithIndex{ group, int index ->
    def config = groupNameField.getRelevantConfig(GlobalIssueContext.getInstance())
    if (!optionsManager.getOptions(config)*.value.contains(group.name)) {
        optionsManager.createOption(config, null, index, group.name)
    }
}
Derek Sheeman
Contributor
May 15, 2017

The select list is exactly what I was planning on doing.  We have too many groups to realistically update the select list.  Jira Admins will have to do it as teams on-board.

Thank you very much for your insight and assistance!

1 vote
Answer accepted
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
May 15, 2017

So... Community apparently nuked my previous answer? Because this question got flagged as spam for no good reason???

Anyway, here's the script again. Create a select list with group names, then add a post function to the create transition that does this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder

def groupManager = ComponentAccessor.groupManager

def customFieldManager = ComponentAccessor.customFieldManager
def groupNameField = customFieldManager.getCustomFieldObjectByName("SelectListA")
def groupNameSelected = issue.getCustomFieldValue(groupNameField)

def group = groupManager.getGroup(groupNameSelected.toString())
def users = groupManager.getDirectUsersInGroup(group)

def approversField = customFieldManager.getCustomFieldObjectByName("Approvers")
log.debug("Approvers: ${issue.getCustomFieldValue(approversField)}")

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
approversField.updateValue(null, issue, new ModifiedValue("", users), changeHolder);

Had some help from this old answer from Mike Whitlock: https://community.atlassian.com/t5/Questions/How-to-set-add-to-a-multiple-user-picker-custom-field-using/qaq-p/283009

Derek Sheeman
Contributor
May 15, 2017

I'm not sure why it got removed.  It certainly resolved my problem.  So I'll say it again, thanks!

Derek Sheeman
Contributor
May 15, 2017

I am running the following as a custom script post function on the create transition.  Team Approvers is a select list where I have placed the specific user groups that are allowed to be approvers.  It is pretty much the same as above, but we will only be manually updating the select list.  Works like a charm and solvs a major problem for us.

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.groupManager

def customFieldManager = ComponentAccessor.customFieldManager
def groupNameField = customFieldManager.getCustomFieldObjectByName("Team Approvers")
def groupNameSelected = issue.getCustomFieldValue(groupNameField)

def group = groupManager.getGroup(groupNameSelected.toString())
def users = groupManager.getDirectUsersInGroup(group)

def approversField = customFieldManager.getCustomFieldObjectByName("Approvers")
issue.setCustomFieldValue(approversField, users)

 

Like • Jonny Carter likes this
TAGS
AUG Leaders

Atlassian Community Events