Can someone help me write a script to dynamically assign an issue to a user? Edited

Hello all!  I am brand new to JIRA and have been presented with the following requirement for a test case workflow:

A lead developer is assigned an issue as default in step 2 via a workflow post function.  This lead developer assigns it to a member of his team to test in this step.  The tester completes their step (step 2) and sends the case for review, deferment, upgrade or what have you.  At some later step (3, 8 or 10) we need to assign the issue back to the tester (not lead developer) as default assignee via a script in the workflow post function.

I would appreciate any assistance in showing me how to write this script. 

2 answers


I think you could do it like this:

add a user custom field which is named tester

when lead developer assigns the issue to the tester , in the post function sets the value to tester user

or when the tester completes his step in post function , set this field with the username of the tester 

and when you need to assign the issue back to the tester, you have just to set value of assignee with tester custom field value in the post function

You can do this using a scripting plugin like power script or  script runner or with java Script which is not recommended.

Good luck

Hi zezeto,

   Thanks for your advice.  I have added the new custom field called "LR Tester" and defined it as a single user picker.  I then found the following code (below) and adapted it to fit my needs.  In the Post Function script checker, I don't get any errors, but when I run through the work flow, it does not copy the value to the LR Tester field and I can see that my script errored out.

The script is as follows:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find { == "LR Tester"}
def assignee = issue.assignee
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), assignee),changeHolder)

Any thoughts on where I went wrong?

@Virgil Corral

soory i don't know script runner

i get used to use jjupin script plugin

0 votes

Rather than writing a script this is probably better handled with post functions. There are numerous great plugins that would be able to help you with this. In particular the "JIRA Suite Utilities" plugin allows you to copy values between fields. If you set a user picker field of "tester" this can then be accessed by these post functions to copy the value of that user picker back into the "Assignee" field. 

This would probably save you a lot of time. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,701 views 3 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you