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

This widget could not be displayed.


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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

715 views 0 3
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