Approvals by User Group Edited

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

Accepted Answer
2 votes

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.

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

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!

Accepted Answer
1 vote

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

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

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)

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 13, 2018 in Jira Service Desk

Jira Service Desk – Don’t be afraid, the journey begins with curiosity!

...be more productive while being fun to use at the same time. For some, getting started can be a bit intimidating. This is especially true if Jira Service Desk is your first exposure to Atlassian...

18,672 views 13 31
Read article

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