Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Adding someone to a user-selected jira group via post function

I'm looking to run a script to add a user to a jira group via a post function. 

Use case:

The manager creates a new ticket "Add user to group" & fills out:

New Hire (custom field, User Picker)

Jira User Group (Custom field, dropdown list) This list will have all possible Jira user groups.

 

I have a script that works if I hard code the jira user group into it, but I want to allow the manager to select the group. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

def groupManager = ComponentAccessor.getGroupManager()
def user = (ApplicationUser) ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requesting Producer").getValue(issue)

def group = groupManager.getGroup("TEST-Group")

groupManager.addUserToGroup(user,group)

 

I've tried to define "group" by changing "groupManager.getGroup()" to defining it by getting the value of my "Jira User Group" custom field, but then I get an error message on the next line that it's not valid for "groupManager.addUserToGroup(user,group)

 

Thank you

 

2 answers

1 accepted

0 votes
Answer accepted
Amanda Kirk
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 Leaders.
Aug 25, 2020

You'll see that the groupManager.addUserToGroup function is taking in a string which is the name of the group.

What you should do is output what you are storing from the Jira User Group field to ensure it is 1) A string and 2) A valid jira group.

If it is a valid jira group and a string you should be able to pass it to the gropManager.addUserToGroup function.

 

When an error says not valid it usually means it is not the right type.

You can always take the value of the custom field Jira User Group and use toString() to make sure it is a string.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events