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!
Community moderators have prevented the ability to post new answers.
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!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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')) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dang, alright.
Hmm. Wait, is the string 'contains' valid for the function 'issue.issueTypeObject.name.contains'? Shouldn't it just be 'issue.issueTypeObject.name'?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
tried it just doing
if (issue.issueTypeObject.name('issue type1'))
and that didnt seem to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.