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

Virgil Corral December 20, 2017

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

1 vote
Nadir MEZIANI
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 20, 2017

Hi,

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

Virgil Corral December 26, 2017

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 {it.name == "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?

Nadir MEZIANI
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.
January 6, 2018

@Virgil Corral

soory i don't know script runner

i get used to use jjupin script plugin

0 votes
Kian Stack Mumo Systems
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2017

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
TAGS
AUG Leaders

Atlassian Community Events