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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Populate a custom field in jira with the name of group the assignee user belongs to

We have a use case where as soon as a jira issue is assigned to a particular user, a custom field (could be regular text field or group picker field), is populated by the name of group the assignee belongs to. In this case any of the users who will be assigned to these issues will always only belong to two groups. One would ofcourse be the default jira-software-users group for login and the other group would be some xyz group and we would like that xyz group to be populated for that user under that custom field. So lets say when assignee is user1 and belongs to groups jira-software-users group and group1 then the custom field is automatically populated with group1 name. If its user2 with same jira-software-users group but this time group2, then that custom field is populated with group2 and so on and so forth.

Is anyone aware of how this could be accomplished. I feel script runner plugin could come handy, but i am a novice in that area, hence any help or suggestions will be greatly appreciated as always.

Cheers,

Ashley

1 answer

Hi @ashleyg you can use listeners of script runner to achieve this (https://docs.adaptavist.com/sr4js/6.19.0/get-started/tutorials/listeners-tutorial).

Events you want to listen are:

  • Issue Updated (it is here because when you edit Assignee on transition screen, Issue Assigned event is not triggered)
  • Issue Assigned

I'm using following code to find out whether Assignee field was changed during Issue Updated:

def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find { assigneeField.equals(it.field) }
if (change) {
def userKey = change.newvalue
...
}

Thanks Martin for the prompt assistance.
As far as the code is concerned how do i enable it to populate my custom field with the name of the other group the assignee user belongs to?

hi @ashleyg you will just need to filter them out. So you will have to:

  1. define "general" groups which you do not want to take into account
  2. go through user's groups and filter this groups out
  3. select ONE group (if you use sinlge group picker field) or ALL THE OTHER GROUPS (if you use multi group picker field)

It could be something like:

def filteredGroupsNames = ['jira-users', 'jira-software-users']
def
userKey = change.newvalue
def user = ComponentAccessor.getUserManager().getUserByKey(userKey)
def userGroups = ComponentAccessor.getGroupManager().getGroupsForUser(user)
def filteredUserGroups = userGroups.findAll {!filteredGroupsNames.contains(it.name)}
// now set filteredUserGroups to your field

Thanks again Martin for clarifying and putting together the code snippet.
I will be using single ggroup picker as my custom field to populate for the assignee user.
So if i were to implement the code you provided, what would be the complete code i can use. I'm not much into groovy and just trying to see if script runner can make it easier for me to implement. For now if i combine your code snippets, here is what i get, i am wondering how do i set the single group picker customfield (you can name it anything like xyz) to set the value that is not the filtered ones which means whatever remains other than jira-users and jira-software-users. We have only one other internal custom group name for each such assignee user so if we filter the common jira-users and jira-software-users, whatever is left out will be the actual group name for that assignee user.

def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find { assigneeField.equals(it.field) }
def filteredGroupsNames = ['jira-users', 'jira-software-users']
def userKey = change.newvalue
def user = ComponentAccessor.getUserManager().getUserByKey(userKey)
def userGroups = ComponentAccessor.getGroupManager().getGroupsForUser(user)
def filteredUserGroups = userGroups.findAll {!filteredGroupsNames.contains(it.name)}

if (change) {
def userKey = change.newvalue
...
}

Ah my bad, i see the catch here :-
def filteredUserGroups = userGroups.findAll {!filteredGroupsNames.contains(it.name)}
so this will only assign the other group that i need, so i guess it should work.

so basically the only final step would be to set the filteredUserGroups to my single group picker custom field. How can i do that in script runner groovy? Doi have to retrieve the custom field id from jira and then use that , just looking for some basic guidance there.
Once i have it all, i will test it in our jira and confirm if that works.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - Spring 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

124 views 3 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you