Forums

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

ScripRunner Copy custom field values from 3 multi-user picker CFs and add those values to another CF

Devops November 28, 2018

Hello Folks,

I am trying to do some automation with Jira service desk with Scriptrunner plugin while creating an issue.This is the scenario.

I need to extract custom field values from 3 multi-user picker custom fields and add those values to another multi-user picker custom field during the ticket creation. I wanted to implement this logic in post-functions.

CF1 - user1,user2
CF2 - userX,userY
CF3 - userA,userB

As soon as some create a ticket, Copy the above 3 CF values (all users) to another custom field (multi-user picker) CF4 = $CF1, $CF2, $CF3

 

Please shed some light on this scenario.

1 answer

0 votes
Elifcan Cakmak
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.
November 29, 2018

Hello,

For this purpose, you need an add-on. For example with Jira Suite Utilities add-on's Copy Value From Other Field (JSU), you can copy three fields' values to another field and use append while doing it.

Or you can use Script Runner to write a custom script to add all these custom fields' values to another. 

However I don't think there is a way to do this with default Jira features.

Regards,

Elifcan

Devops November 29, 2018

Thank you @Elifcan Cakmak.

Actually, I was using the Script-runner plugin for this and forgot to add it up in the description. Let me edit the question.

I wanted to have the scriptrunner script for this use case.

Elifcan Cakmak
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.
November 30, 2018

Hello,

A script like below could help you:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.UpdateIssueRequest

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("KP-15")
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def user = authenticationContext.getLoggedInUser()

def usergroup1 = customFieldManager.getCustomFieldObject("customfield_10801")
def usergroup2 = customFieldManager.getCustomFieldObject("customfield_10022")
def usergroup3 = customFieldManager.getCustomFieldObject("customfield_10800")
def allusersgroup = customFieldManager.getCustomFieldObject("customfield_10824")

def usergroup1users= issue.getCustomFieldValue(usergroup1)
def usergroup2users= issue.getCustomFieldValue(usergroup2)
def usergroup3users= issue.getCustomFieldValue(usergroup3)

def allusers = usergroup1users + usergroup2users + usergroup3users

issue.setCustomFieldValue(allusersgroup, allusers)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Ofcourse you will need to remove line below to add it to your postfunction.

def issue = issueManager.getIssueObject("KP-15")

 Regards,

Elifcan

Devops November 30, 2018

Thank you so much @Elifcan Cakmak for your help on this issue.

I have ran the above script with my own customfield Ids and got the compilation error.error.jpg

Elifcan Cakmak
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.
December 1, 2018

Hello,

I got the same error (Cannot find matching method) but it still worked. I think it's because one of the user groups custom field is empty. If there is such possibility, you should add a check that controls if the user group is empty.

Regards,

Elifcan

Suggest an answer

Log in or Sign up to answer