Forums

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

create custom scripted field in scriptrunner

Samar Elsayed October 21, 2021

Hi,

 

So 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 :

,,,,,,,,

 

 

1 answer

0 votes
Nic Brough -Adaptavist-
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.
October 22, 2021

Ok, there's not quite enough detail here for us to be able to help much.  Not on the script, that's fine, but we need to know more about what you're trying to achieve and exactly how.  There's no point in us writing up one solution if it doesn't apply because you are doing something different.

The crux of this is "what is the target field for?".  Is it intended to display a list of groups the editor is in at the time of the create/edit/transition?  Should it be a list of groups that the editor is going to select one or many of?  Or something else?

samar_mahran October 23, 2021

Hi @Nic Brough -Adaptavist- 

thanks for the reply, so I have 2 postfunctions, one to add user/s to group/s and the other to remove and these postfunctions only the admin of the project can use.

I have a field for user picker and  another field that is a multi choice and has the names of certain groups names depending on the project using that field ( I did that so no one from the project can manage any groups except what appears to the member of the project. 

instead of creating a context of that multi choice field ( group ) to each project, I am trying to make it dynamic so that it shows only the groups the user belongs to.

(I will add later a condition where jira admin is excluded from the result  but I need to make it work first)

Suggest an answer

Log in or Sign up to answer