Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi,
I want to add a postfunction script that sets the assignee based on a custom fields value.
So for example when field a has value 1 then it should be assigned to person 1. If it's value 2 then it should be person 2. We do have scriptrunner, can anybody tell me how the script should look to enable this?
Here it is. It could be some changed based on custion field type.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue String userName; switch(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldname").toString()){ case "1": userName = "user1";break; case "2": userName = "user2";break; case "3": userName = "user3";break; } issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
Thanks Vasiliy! Greatly appreciated!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have a similiar task to perform, but instead of the assignee I want to set the UserPicker-field, which we use for defining the approver.
Therefor the script should only be valid for our two workflows, which have approval-steps.
So if our employees enter their department, the manager should be set automatically for the following approval.
Best regards, Thomas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vasiliy Zverev,
I have the exact same problem to solve, but when I used your corde in a Jython post-function script I get the following error:
SyntaxError: ("mismatched input 'userName' expecting NEWLINE", ('<string>', 4, 7, 'String userName;\n'))
It seems that you have tried to perform an illegal workflow operation.
Do you have any idea why this is happening?
My code so far is:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
String userName;
switch(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Custom Field").toString()){
case "A": userName = "User A";break;
case "B": userName = "User B";break;
case "C": userName = "User C";break;
}
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
where "Custom Field" is a custom field defined by a single-choice select-list.
Thanks in advance!
Best regards,
Hector
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Hector,
You can try this script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
String user;
def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObjectByName("Select List Field");
switch(issue.getCustomFieldValue(cf) as String){
case "1": user = "username1";break;
case "2": user = "username2";break;
case "3": user = "username3";break;
}
issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it possible to set the assignee based on a cascading custom field? I would like to have a condition that checks the first and second value of a cascading list and assigns a user based on both values.
For example:
1) Product A / Component B = user1
2) Product B / Component E = user2
Can someone help me with a scriptrunner script for this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Gavin Minnis Did you get a solution for Your query to handle cascading fields selection?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Answer removed and transferred to ticket https://community.atlassian.com/t5/Jira-questions/Auto-Assignation-Issues/qaq-p/1121010
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Experts,
I am trying the script suggested above by Vasiliy. however my issues remain unassigned.
I am putting the script on Create transition of the workflow.
Also i want to do this for a cascading field, how can I acheive that?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssueString userName;
switch(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Combo Onestack").toString()){
case "Jira + Confluence + Bitbucket + Add-ons": userName = "Seba.Sosa";break;
case "Jira + Confluence + Add-ons": userName = "smittal";break;
case "Jira + Add-ons": userName = "cprado";break;
}issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
Thanks in anticipation.
Sakshi
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.