As stated in the summary, during the creation of the issue a component is set based on a list custom field and assigned to the reporter. Each component lead is a manager and I'm attempting/failing at trying to have the component lead populated to a manager field (custom user picker field). Unfortunately, I'm having a really hard time figuring out how to set a custom user picker field based on a component lead. In this situation, the list option is the same as the component's name.
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
ProjectComponentManager componentManager = ComponentAccessor.projectComponentManager
def userCf = customFieldManager.getCustomFieldObject(10094)
CustomField selectList = customFieldManager.getCustomFieldObject(14760L)
Option selectListValue = issue.getCustomFieldValue(selectList) as Option
if (selectListValue)
{
String componentName = selectListValue.getValue()
ProjectComponent component = componentManager.findByComponentName(issue.projectObject.getId(), componentName)
if (component)
{
issue.setComponent([component])
def Lead = issue.getComponents().getAt(0)?.getLead()
issue.setCustomFieldValue(userCf, Lead)
}
}
I would really appreciate any help or anything that could point me in the right direction. Also, if there are any related issues on how to set a custom user picker field or getting a user, I would be very thankful.