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

How to copy users from a group to a user field

Hello! Hope everyone is safe and health!

I'm looking for a way to insert users from a group field to a multiple user field.

I'm trying to solve this with Scriptrunner Cloud, but I can't insert the accountID user's on the the field.

 

Thanks for the help!

1 answer

1 accepted

0 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 14, 2020

@Ricardo Cardoso D_ Oliveira  it should be something like this:

def issueKey = 'DEMO-9'

// Fetch the issue object from the key
def issue = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body

// Get all the fields from the issue as a Map
def fields = issue.fields as Map

// Get the Custom field to get the option value from
def customFields = get("/rest/api/2/field")
.asObject(List)
.body as Map

def someGroupCfId = customFields.find { it.name == 'Some Group' }?.id
logger.error(someGroupCfId)

def someUsersCfId = customFields.find { it.name == 'Some Users' }?.id
logger.error(someUsersCfId)

def someGroupCfValueGroupName = (fields[someGroupCfId] as Map)?.name
logger.error("Selected Group:" + someGroupCfValueGroupName)

// Extract and store the option from the custom field
def someUsersfValuesUsers = (fields[someUsersCfId] as Map)?.toString()
logger.error("Selected users:" + someUsersfValuesUsers)

def members = get("/rest/api/3/group/member?groupname=${someGroupCfValueGroupName}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body as Map

def membersAccounts = members.values.collect{it.accountId}
def membersAccountsParam = []
membersAccounts.forEach {
membersAccountsParam.add([accountId: it])
}
logger.error("asdasdasd:"+membersAccountsParam)
logger.error("members:"+membersAccounts.toString())

def result = put('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.body([
fields:[
// The custom field representing my user picker field
customfield_10041: membersAccountsParam
]
])
.asString()

  • Single group picker CF has name "Some Group" 
  • Multi user picker CF has name "Some Users" 

Let me know if it's working.

@Martin Bayer _MoroSystems_ s_r_o__ may you please help me change this script to use in jira automation. My requirement is to copy users from a group from a custom field named Watchers group to a multi user field named watchers list. I am using Jira Cloud

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events