Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help to write ScriptRunner script to assign issues to certain users based on issue type

Tennille Noach February 4, 2019

HI,

 

I need help to write the script to use for the following example.

 

I have an issue type within a project with four different sub-tasks that can be created. Each of the sub-tasks needs to be automatically assigned to a particular user. I have inserted a post-function into the workflow which I want to run a script so that:

If issuetype = 1 then make assignee = userA,

If issuetype = 2 then make assignee = userB,

If issuetype = 3 then make assignee = userC,

If issuetype = 4 then make assignee = userD

 

I am really unsure of how to write the full script that would do this, can anyone please assist?

 

Many Thanks

1 answer

1 vote
Elifcan Cakmak
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.
February 5, 2019

Hello,

Below script should work for your need. You should change the issuetype names and users, of course. 

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

def subtaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
def issuetype = issue.getIssueType()

if(issuetype.name == "Sub-task") {
issue.setAssigneeId("user1")
} else if(issuetype.name == "Task") {
issue.setAssigneeId("user2")
} else if(issuetype.name == "Story") {
issue.setAssigneeId("user3")
} else if(issuetype.name == "Bug") {
issue.setAssigneeId("user4")
}

issue.store()

 Regards,

Elifcan

Tennille Noach February 6, 2019

Thanks so much for your time Elifcan, I am about to give it a go and see what happens!

Cheers

Tennille

Tennille Noach February 6, 2019

Hmmmm the last line is showing an error  issue.store()   ?

 

script error.PNG

Tennille Noach February 6, 2019

I removed the last line from the script just to see if it would work, and it seemed to look ok in the field where the code is written i.e. the green light indicated that there were no errors in the script, but when I update the workflow and then try to test it, none of the sub-tasks are updated with the individual users specified to be Assignees in the script - it just keeps adding the Project Lead as the default Assignee?

 

I used this version of the script:

 

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

def subtaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
def issuetype = issue.getIssueType()

if(issuetype.name == "System Access") {
issue.setAssigneeId("beatrice.d");
} else if(issuetype.name == "Access Pass") {
issue.setAssigneeId("mark.a");
} else if(issuetype.name == "Profile") {
issue.setAssigneeId("cameron.x");
} else if(issuetype.name == "SSO") {
issue.setAssigneeId("gosia.p");
}else {issue.setAssigneeId("kristina.m");

}

 

Any ideas?

Suggest an answer

Log in or Sign up to answer