Hello!
I have custom field called Test Phase which is a single select list. I want to assign the issue to user AA when "Prod" selected and to user BB when "Dev" selected in Test Phase.
I am new to script runner and I tried following script and failed. Can you please check and let me know the problem of this script?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Test Phase")
def cfTestPhase = issue.getCustomFieldValue(cf)
switch(issue.getCustomFieldValue(cfTestPhase)){
case "Prod": userName = "AA";break;
case "DEV": userName = "BB";break;
}
log.error(userName)
log.error(issue.getCustomFieldValue(cfTestPhase));
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
Hello,
Where do you put the script?
Your script should look like this and you should assign the user name to the userName variable not the user display name
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Test Phase")
def cfTestPhase = issue.getCustomFieldValue(cf)
switch(cfTestPhase){
case "Prod": userName = "AA";break;
case "DEV": userName = "BB";break;
}
log.error(userName)
log.error(cfTestPhase);
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alexey Matveev,
Thank you for your reply. I tried the script and it still doesn't assign the issue to the right person but the default person.
We use our employee Ids as our username in JIRA. So AA and BB replaced by related user ids.
I put the script as a create post function in the workflow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should put the script last in the post function list. Could you provide a screenshot for the create transition with all the post-functions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Logs are as follows,
E2222222 is the employee number of the assignee.
Possible solutions: setAssignee(com.atlassian.crowd.embedded.api.User), getAssignee(), setAssigneeId(java.lang.String), getAssigneeId()
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setAssignee() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser) values: [E2222222]
2017-12-22 15:03:37,355 http-bio-8081-exec-9 ERROR e1111111 903x23900x1 1gkcy9a 10.56.32.65 /secure/QuickCreateIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: BT-12, actionId: 1, file: <inline script>
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 guess your Jira Version is less than 7.x.x, is not it? Try this script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Test Phase")
def cfTestPhase = issue.getCustomFieldValue(cf)
switch(cfTestPhase){
case "Prod": userName = "AA";break;
case "DEV": userName = "BB";break;
}
log.error(userName)
log.error(cfTestPhase);
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssignee(ComponentAccessor.getUserManager().getUser(userName))
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
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.
This script works like a charm. You saved my time today!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are aware of components and component leads yes?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Alexey Matveev You never know right =)
BTW would love to chat with you offline sometime. Drop me an email if interested. ethan at theresponsiveproject dot com
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I am but it doesn't fix with my requirement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alexey Matveev,
The script works well I have combined it with other custom field as well.
I have a another requirement if user change the assignee during the transition, it should overwrite the auto assignee value.
Do you have any idea how to do that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I saw your question. But I could not figure it out how to set the auto assignee value with ScriptRunner behaviours. I wanted to dig deeper into the source code of Scriptrunner to see if it is possible, but unfortunately I did not have time for it. Maybe someone from Adaptivist will answer the question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.