Groovy Script reassing issue

Hi Guys,

I'm try to write some groovy script what should re-assign issue based on current assignee, but it wont work not even start. JIRA what I use is 6.3.15 and SR version is 3.1.3. I'm running script as a post function


Code of my Script. Thanks in advice for Help

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
 
MutableIssue issue = issue;
def userManager = ComponentAccessor.getUserManager()
    def Admin1 = userManager.getUserByName('Admin1')?.directoryUser
	def User1 = userManager.getUserByName('User1')?.directoryUser
    def Tester1 = userManager.getUserByName('Tester1')?.directoryUser
    def Admin2 = userManager.getUserByName('Admin2')?.directoryUser
    def User2 = userManager.getUserByName('User2')?.directoryUser
    def Tester2 = userManager.getUserByName('Tester2')?.directoryUser
	
//Team 1
	
    if(issue.assignee.equals(Admin1)) {
        issue.setAssignee(Tester1)}
		
	    if(issue.assignee.equals(User1)) {
        issue.setAssignee(Tester1))}
		
		    if(issue.assignee.equals(User1)) {
			issue.setAssignee(Tester1))}
//Team 2	
	if(issue.assignee.equals(Admin2)) {
        issue.setAssignee(Tester2)}
		
		if(issue.assignee.equals(User2)) {
        issue.setAssignee(Tester2))}
		
			if(issue.assignee.equals(User2)) {
			issue.setAssignee(Tester2))}

 

3 answers

1 accepted

This widget could not be displayed.

Your script should look like the following. Note i've used == in the if statement and camel-cased variable names so its more readable.

This should set the assignee for you on the transition.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = issue;
def userManager = ComponentAccessor.getUserManager()
def admin1 = userManager.getUserByName('Admin1')?.directoryUser
def user1 = userManager.getUserByName('User1')?.directoryUser
def tester1 = userManager.getUserByName('Tester1')?.directoryUser
def admin2 = userManager.getUserByName('Admin2')?.directoryUser
def user2 = userManager.getUserByName('User2')?.directoryUser
def tester2 = userManager.getUserByName('Tester2')?.directoryUser

//Team 1
if (issue.assignee == admin1) {
    issue.setAssignee(tester1)
}

if (issue.assignee == user1) {
    issue.setAssignee(tester1)
}

if (issue.assignee == user1) {
    issue.setAssignee(tester1)
}
//Team 2
if (issue.assignee == admin2) {
    issue.setAssignee(tester2)
}

if (issue.assignee == user2) {
    issue.setAssignee(tester2)
}

if (issue.assignee == user2) {
    issue.setAssignee(tester2)
}

Sitll error sad . I have it first as post function and in place of "Admin1" my username form JIRA right ?

Do you see any error messages? Anything in the logs to indicate what the problem is?

2016-05-12 13:28:20,017 http-bio-8443-exec-7 ERROR mbeczynski 808x33394x1 1nspkgu 195.205.243.130 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2016-05-12 13:28:20,018 http-bio-8443-exec-7 ERROR mbeczynski 808x33394x1 1nspkgu 195.205.243.130 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: SGSP-53, actionId: 711, file: /var/atlassian/application-data/jira-production/scripts/InProgressToCodeReview.groovy


Only This nothing what could help me 

Can you try removing all of your script and just having the following line in it and seeing if that runs correctly? If that works then its likely to be an error in the script.

log.warn("Running script")

Nothing at console, so it can be something wrong with JIRA or Script Runner plugin ??

Do you still see same error message in the logs? 

016-05-12 13:28:20,017 http-bio-8443-exec-7 ERROR mbeczynski 808x33394x1 1nspkgu 195.205.243.130 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2016-05-12 13:28:20,018 http-bio-8443-exec-7 ERROR mbeczynski 808x33394x1 1nspkgu 195.205.243.130 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: SGSP-53, actionId: 711, file: /var/atlassian/application-data/jira-production/scripts/InProgressToCodeReview.groovy

nope it just show nothing at all, I made perform reindexing now maybe that will resolve this issue 

It seems like the post-function isn't firing. Do you have permission to do the transition?

yep I had all permission it start work after re index instance + clear cache and groovy internal cache and re index issue at project . Thanks you for your time and help if you will be at Poland let me know I own you a beer 

This widget could not be displayed.

Your script won't compile. You have extra ')' near the if statements. Are you adding this script as part of a post-function or listener? More details would be good so I can give you a more useful answer.

This widget could not be displayed.

. I'm running script as a post function 

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
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

128 views 2 0
Join discussion

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