Hi all,
i'm trying to set the assignee based on 2 different custom field values (Process & IT department) as an post-function in a workflow transition. Both fields are implemented in a screen which pops up during the transition. I've tried it with the following code (w. script runner):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUsers
import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE
MutableIssue issue = issue;
String userName;
def e2e = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("E2E process (main)")
def dep = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("IT department")
String assGroup;
if (e2e == "Value 1" && dep == "Value A"){
assGroup = "1"
} else if (e2e == "Value 2" && dep == "Value A"){
assGroup = "2"
} else if (e2e == "Value 3" && dep == "Value B"){
assGroup = "3"
} else if (e2e == "Value 4" && dep == "Value C"){
assGroup = "4"
} else if (e2e == "Value 5" && dep == "Value D"){
assGroup = "5"
} else if (e2e == "Value 6" && dep == "Value E"){
assGroup = "6"
} else if (e2e == "Value 7" && dep == "Value F"){
assGroup = "7"
} else if (e2e == "Value 8" && dep == "Value G"){
assGroup = "8"
} else if (e2e == "Value 9" && dep == "Value H"){
assGroup = "9"
} else if (e2e == "Value 10" && dep == "Value I"){
assGroup = "10"
} else if (e2e == "Value 11" && dep == "Value J"){
assGroup = "11"
} else if (e2e == "Value 12" && dep == "Value K"){
assGroup = "12"
} else if (e2e == "Value 13" && dep == "Value L"){
assGroup = "13"
} else if (e2e == "Value 14" && dep == "Value M"){
assGroup = "14"
} else if (e2e == "Value 15" && dep == "Value N"){
assGroup = "15"
} else if (e2e == "Value 16" && dep == "Value O"){
assGroup = "16"
}
switch (assGroup.value){
case assGroup = "1" : userName = "sys.user1"; break;
case assGroup = "2" : userName = "sys.user2"; break;
case assGroup = "3" : userName = "sys.user3"; break;
case assGroup = "4" : userName = "sys.user4"; break;
case assGroup = "5" : userName = "sys.user5"; break;
case assGroup = "6" : userName = "sys.user6"; break;
case assGroup = "7" : userName = "sys.user7"; break;
case assGroup = "8" : userName = "sys.user8"; break;
case assGroup = "9" : userName = "sys.user9"; break;
case assGroup = "10" : userName = "sys.user10"; break;
case assGroup = "11" : userName = "sys.user11"; break;
case assGroup = "12" : userName = "sys.user12"; break;
case assGroup = "13" : userName = "sys.user13"; break;
case assGroup = "14" : userName = "sys.user14"; break;
case assGroup = "15" : userName = "sys.user15"; break;
case assGroup = "16" : userName = "sys.user16"; break;
}
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
Anyone has a clue?
Thank and best regards,
Vedat
Your if clauses should look like this:
if (issue.getCustomFieldValue(e2e).toString() == "Value 1" && issue.getCustomFieldValue(dep).toString() == "Value A"){
and at the end of the scripts there must be
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Tried it like this, but did'nt work. My script runs with no errors, but the issue is still UNASSIGNED after the transition. Any idea?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is what works now. Thanks Alex!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.event.type.EventDispatchOption
import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE
MutableIssue issue = issue;
String userName;
def e2e = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("E2E process (main)")
def dep = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("IT department")
String assGroup;
if (issue.getCustomFieldValue(e2e).toString() == "Process 1" && issue.getCustomFieldValue(dep).toString() == "Department Value 1"){
assGroup = "1"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 2" && issue.getCustomFieldValue(dep).toString() == "Department Value 1"){
assGroup = "2"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 3" && issue.getCustomFieldValue(dep).toString() == "Department Value 1"){
assGroup = "3"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 4" && issue.getCustomFieldValue(dep).toString() == "Department Value 2"){
assGroup = "4"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 5" && issue.getCustomFieldValue(dep).toString() == "Department Value 2"){
assGroup = "5"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 6" && issue.getCustomFieldValue(dep).toString() == "Department Value 2"){
assGroup = "6"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 7" && issue.getCustomFieldValue(dep).toString() == "Department Value 3"){
assGroup = "7"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 8" && issue.getCustomFieldValue(dep).toString() == "Department Value 3"){
assGroup = "8"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 9" && issue.getCustomFieldValue(dep).toString() == "Department Value 3"){
assGroup = "9"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 10" && issue.getCustomFieldValue(dep).toString() == "Department Value 3"){
assGroup = "10"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 11" && issue.getCustomFieldValue(dep).toString() == "Department Value 4"){
assGroup = "11"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 12" && issue.getCustomFieldValue(dep).toString() == "Department Value 5"){
assGroup = "12"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 13" && issue.getCustomFieldValue(dep).toString() == "Department Value 6"){
assGroup = "13"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 14" && issue.getCustomFieldValue(dep).toString() == "Department Value 7"){
assGroup = "14"
} else if (issue.getCustomFieldValue(e2e).toString() == "Process 15" && issue.getCustomFieldValue(dep).toString() == "Department Value 8"){
assGroup = "15"
}else if (issue.getCustomFieldValue(e2e).toString() == "Process 16" && issue.getCustomFieldValue(dep).toString() == "Department Value 9"){
assGroup = "16"
}
switch (assGroup){
case "1" : userName = "user 1"; break;
case "2" : userName = "user 2"; break;
case "3" : userName = "user 3"; break;
[......]
}
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Celik Vedat You are welcome. I am glad it works for you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I ran into this issue also. Simple answer is you cannot because the values set in a transition screen are not reliably (and most times not) available during the post function since they are set asynchronously.
Convert your post function to a listener and trigger off issue update within the project for the issue type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What you mean is creating a listener in Script-Listeners > Custom script and select the event ISSUE UPDATE right? Can you explain in detail how to modify my code so it fits for the listeners? What's new to me is: How can I refer to my Transition Action?
Best,
Vedat
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.