Need help with JIRA groovy script

Hi - I am having some trouble getting a post function script to run in JIRA.  I am very inexperienced in coding and do not know why I keep getting the error that [issue] is undeclared.  This is JIRA v6.


The purpose of this post function script is to update Assignee based on Issue Type:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.config.SubTaskManager
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.user.UserUtils
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.util.UserManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.component.ComponentAccessor

if( == 'Story') {
else if( == 'Bug') {
else if ( == 'Problem') {

2 answers

1 accepted

0 votes
Answer accepted

This has been resolved.  Although the script console gave me that error, it seemed to execute perfectly when put inside the post-create workflow transition as follows:

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.Issue

if( == 'Bug') {
else if( == 'Problem') {
else if ( == 'Defect') {

Did you test the scirpt? 
Did it actually assigned the issue to the inteneded user just like this without validation?

Yes, I did test it and it worked inside the project context in the workflow transition script. 

It assigns to the specific user set in the script, however, this needs to be placed at the correct step in the create issue post functions. 

0 votes
Steven Behnke Community Champion Sep 07, 2017

Can you show us where you're using this script? Also, you don't need any of those IMPORT statements. 

I am using this as a script after creating an issue that would assign to a specific user based on the issue type. 

This would go in the "post condition" for the create transition. 

When I type it in the script console I get a "[issue] variable not declared"

I am stummed at this as well. 
In the following, I am just getting an issue, a user, and assigning the issue to that user. 

Why is this not working?
It just keeps returning null without changing the assignee.

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()

def user = userManager.getUserByName("tbas")

def issueObject = issueManager.getIssueObject("HW_TEST-64")
def issueType = issueObject.getIssueType().name


 The logic makes sense, the method here says it should work aswell? See this.

I am running this in ScriptRunner's console, just for testing purpose. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


261 views 0 6
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