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!
@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()
Let me know if it's working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.