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

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

How to copy the current user to custom field using ScriptRunner Edited

During a workflow transition I'm attempting to copy the value of the current assignee into a single user custom field, then separately add the current user (the person clicking the button that  does the transition) into another single user customfield. 

Please can someone help me write the Groovy script for Scriptrunner?

1 answer

1 accepted

Hi @Leslie Baker

For your requirement, you can try out something like this:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issue = issue as MutableIssue
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def assignee = issue.assignee

def userPicker = customFieldManager.getCustomFieldObjectsByName("User Picker")[0]
def currentUser = customFieldManager.getCustomFieldObjectsByName("Current User")[0]

issue.setCustomFieldValue(userPicker, assignee)
issue.setCustomFieldValue(currentUser, loggedInUser)

 Below are a few test screens for your reference:-

You will need to use the Custom Script option in the Post-Function as shown below:-


1) First when the ticket is created only basic info is entered and the assignee is selected as shown below:-


2) Once the ticket has been created, only the Report and Assignee are visible as shown below:-


3) Next, when the issue is transitioned to In Progress, the additional single user picker fields are displayed as shown below:-


I hope this helps to answer your question. :)

Thank you and Kind Regards,


Thanks so much, that's done the trick.

only tweak was the variable name for issue to iss as it confuses with the other 'issue' but otherwise spot on!

Suggest an answer

Log in or Sign up to answer

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