Hello Community, I need help on scriptrunner, I need to set assignee based on the component's lead. Below is the code that I'm using
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
// a map with select list option to Component
def componentsMap = [
"BOSS" : "Component1",
"Mashery" : "Component2",
]
def issue = event.issue as MutableIssue
def selectList = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Affected Service")
def selectListValue = issue.getCustomFieldValue(selectList) as LazyLoadedOption
// there is no value for the select list - therefore do nothing
if (! selectListValue) {
return
}
def componentManager = ComponentAccessor.projectComponentManager
def componentName = componentsMap.get(selectListValue.value)
def component = componentManager.findByComponentName(issue.projectObject.id, componentName)
def userManager = ComponentAccessor.userManager
def components = issue.componentObjects.toList()
if (component) {
componentManager.updateIssueProjectComponents(issue, [component])
}
issue.setAssignee(ComponentAccessor.userManager.getUserByKey(component.lead))
In this code, I have Affected Service as a single select list, if BOSS has been selected, the Component Field will update and set to Component1, but the assignee remains unassigned even if I have default assignee on my component. I know that there's something wrong with my code because I'm a beginner. I need to change assignee everytime component field is changed, that's why I used script listener. Thanks
Hello @Drishti Maharaj ,
I just tried your script. It is working fine, I only had to add this line at the end to update the issue :
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getUserManager().getUserByKey('user_key'), issue, EventDispatchOption.DO_NOT_DISPATCH, false);
Of course you will need to map all the priorities in your switch but that does not seem to be the issue.
Let me know if that helped.
Hi @Antoine Berry , thank you for taking the time to reply, if I add the additional script from you, the following error occurs:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , I managed to figure out what was wrong :)
Just needed this at the top:
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
and it worked perfectly!
Thank you so much!
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.