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

How to copy users from a group to a user field

Ricardo Cardoso D_ Oliveira August 13, 2020

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.
August 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.

Ricardo Cardoso D_ Oliveira August 14, 2020

@Martin Bayer _MoroSystems_ s_r_o__ works perfectly!!!

 

Thank you very much!

Abdul Majeed Syed October 31, 2023

@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