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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,788
Community Members
 
Community Events
184
Community Groups

create custom scripted field in scriptrunner

Hi,

I need to get the groups that the logged in user belongs to and make these groups appear as options in a multi choice custom field.

below is the code that gets the groups :

 

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level


def logg = Logger.getLogger("")
logg.setLevel(Level.DEBUG)

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def groupManager = ComponentAccessor.groupManager

def group
def g_group
//def userManager = ComponentAccessor.userManager
//def userUtil = ComponentAccessor.userUtil
//

def groupsval = ComponentAccessor.groupManager.getGroupNamesForUser(user) as List

//return groupsval
for(int k=0; k<groupsval.size(); k++) {
group = groupsval.get(k)
// g_group = groupManager.getGroupObject(group)

return group

}

 

How can I do that in script runner ?

 I tried to create a multi group picker scripted field with multi group picker searcher but it gives me empty result as shown below :

,,,,,,,,

1 answer

0 votes
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 22, 2021

Hi @Samar Elsayed ,

I have modified your snippet a bit, could you try this one : 

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level


def logg = Logger.getLogger("")
logg.setLevel(Level.DEBUG)

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def groupsval = ComponentAccessor.groupManager.getGroupsForUser(user)
return groupsval

Antoine

Hi @Antoine Berry ,

 

I have tried that already but it still gives me :

,

 

I have tried to use a custom template instead of group picker :

Capture.PNG

but it gives me the whole list when I use only 

return groupsval

 as below :

[confluence-administrators, agile team]

and when I use the for loop for the list, I get the first element only :

 

Capture.PNG

Like Antoine Berry likes this

@Antoine Berry  do you know how can I get all the groups to appear as options not just one? 

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 25, 2021

Hi @Samar Elsayed ,

This is my configuration : image.png

Using my script above, this is the output on the view screen of an issue : image.png

As you can see this is working correctly. Please remember that a script field only calculates values, but does not provide a list of option (meaning that it will only be available on view screen).

If you want the user to select a group among the user groups, you would need to create a group picker, and update options with a behaviour script.

@Antoine Berry thank you. can you please give me an example about how to do that in 

a behaviour ?

Like Antoine Berry likes this
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 27, 2021

Hi @Samar Elsayed ,

Actually using a group picker field, I think you could only auto-select the user's groups, but not restrict its values.

You could restrict the values of a regular select list, but this would mean having all the groups as options in the field configuration (= a lot of maintenance).

Alternatively you could throw an error if the group selected is not one of the current user's.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events