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
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
Thanks so much for your time Elifcan, I am about to give it a go and see what happens!
Cheers
Tennille
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.
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?
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.