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

Workflow post function to copy custom field to assignee

I want to use a custom script as a scriptrunner transition post function to set the assignee based on the value of a custom user field ("Implemented by"):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser

def userUtil                          = ComponentAccessor.getUserUtil();
UserManager userManager               = ComponentAccessor.getUserManager()

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cfImplementedByField      = customFieldManager.getCustomFieldObject('customfield_11142')
def cfImplementedByValue              = issue.getCustomFieldValue(cfImplementedByField)
ApplicationUser implementedBy         = userManager.getUserByName(cfImplementedByValue?.displayName)

if (implementedBy != "" && implementedBy != null) {

I get the following error:

Screen Shot 2016-02-26 at 14.41.09.png

How to I get to recognize the script, that the custom field value is a user?

4 answers

1 accepted

1 vote
Answer accepted

Hi Flamio,

I have attached a sample script which take the value from a custom user picker such as one called Implemented By and set it to the Assignee field during a transition.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

// Get required Managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// get a pointer to the Implemented By user picker field and its value
def userCf = customFieldManager.getCustomFieldObjectByName("Implemented By")
def implUser = issue.getCustomFieldValue(userCf) as ApplicationUser

// If the Implemented By Field is not null then set the assignee

I hope this helps.





Hi Flamio,

If this answer is now working as expected could you please accept it so that users who have a similar query can easily find the solution.



Thank you, your solution works. There is some strange effect on a Kanban board though. When a user drag&drops an issue into a column, which triggers the transition with the post function script, the assignee is set, but the user avatar is not displayed on the board. Even a refresh doesn't help. Do I need to trigger some sort of manual refresh here somehow?

Hi Flamio,

I have looked at this and noticed the line in the if should be changed to issue.setAssigneeId(implUser.username.toString()) as the setAssigneeId method expects the username of the user.

I have updated the example code above. This new code should set the avatar on the Kanban board.

I hope this helps.



That did it. Thank you very much!

I'm having difficulty with the same issue... I can't get the script suggested above to work, though maybe there is some deprecated code? There are no errors in ScriptRunner, it just isn't working properly. 

I am having the same experience. No error, just unassigned sub-tasks. Any resolution yet?

No idea what issue I had before (I don't remember), but it looks like I went with something following the pattern of the example code above. 

Could have been that the post-function was placed before "Creates the issue originally." or something



I'm using your code defined as an additional action on the "Clones an issue and links" built-in script (Scriptrunner for JIRA), as can be seen in below screenshot:


In the main Story we are defining the "8-LP-Assignee" User Picker field during one of the transitions. The above mentioned script is being defined as a Post-Function in this same transition, which is cloning the issue into another project.

Result is the following:

- For some users, the assignee of the cloned issue has been set correctly towards the person defined earlier in the "8-LP-Assignee" field.

- For other users, the value of the assignee field is being showed as the username in the View issue screen, as e.g. below:


Problem is that the user has not been set correctly as no hyperlink is shown towards the user in the Search Issue screen:

image.pngWhen I click on the assignee field and directly click on enter, the real person is getting defined, as apparently now JIRA is going to lookup the correct person with as a result that the real name is being shown instead of the username:



By using the Script Console, you can see what JIRA is defining in the issue.assignee field, BEFORE and AFTER selecting the assignee field manually and clicking on enter as explained above:





Remark the difference of capital and small letters as username between the brackets.


Can anyone help me out here in order to solve this problem?


Thanks a lot.


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,894 views 11 5
Join discussion

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