Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Help on script to set assignee based on issue type

Adam White May 26, 2016

Hi all,

 

I am trying to avoid creating multiple workflows to set the assignee based on issuetype. Here is the script I came up with. I put it at the bottom of the post-function list for 'Create', but it doesnt seem to be working. It still assigns to the project lead. Do you guys have any ideas?

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager

def Issue issue = issue


if (issue.issueTypeObject.name.contains('Issue Type 1') {
    issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('user1'))
}

    if (issue.issueTypeObject.name.contains('Issue Type 2'') {
            issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('user2'))
}

else {
    issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('user3'))
}

 

Thank you!

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
105349
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.
May 26, 2016

Hey Adam!

Is there any particular reason you'd like to avoid workflows to accomplish this?  To me, using a script seems like it'd be a pain to administer over time, as people change roles, issue types scale, etc.  

Take a look at this document, which outlines how to accomplish this using workflows:

How to automatically assign an Issue to a user, based on Issue Type

I'll dig around and see if I can figure out why your script isn't working, too!

Adam White May 26, 2016

Hey Cody, I am aware you can do this using separate workflows. We have far too many workflows as it is, so this is a way to cut that number down. All of the steps are the same, it seems silly to have to make different flows only for this for many reasons. It actually is easier to do it by script for this particular scenario.

 

I realize in the script I am calling ComponentManager but I actually imported ComponentAccessor. I'm sure that's one reason it isnt working.

 

Don't I also need to be concerned about the index when setting the assignee? Seems like I am missing that piece as well.

105349
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.
May 26, 2016

Hmm, alright.  

Let's try removing a variable from all of this and see what happens.

Browse to the project administration summary page, and under Roles, click on View Project Roles.  On that page, change the Default Assignee to Unassigned, and try the script again.

And yeah, I'm looking to see if you missed a module import, but aside from ComponentManager, I think you're good.

As for the index, it shouldn't cause an issue setting the assignee in this fashion.

Adam White May 26, 2016

I also tried this one and it also did not work

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

userManager = ComponentAccessor.getUserManager()
ComponentManager componentManager = ComponentManager.getInstance()
MutableIssue issue = issue

if (issue.issueTypeObject.name.contains('Type1')) {
    issue.setAssignee(userManager.getUser('user1'))
}
if (issue.issueTypeObject.name.contains('Type2')) {
    issue.setAssignee(userManager.getUser('user2'))
}
else {
    issue.setAssignee(userManager.getUser('user3')) }
Adam White May 26, 2016

I tried it out with Unassigned and still no dice.

105349
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.
May 26, 2016

Dang, alright.

Hmm.  Wait, is the string 'contains' valid for the function 'issue.issueTypeObject.name.contains'?  Shouldn't it just be 'issue.issueTypeObject.name'?

Adam White May 27, 2016

tried it just doing 

if (issue.issueTypeObject.name('issue type1'))

and that didnt seem to work.

TAGS
AUG Leaders

Atlassian Community Events