Greetings! First I wanted to thank the community for being so helpful. I found a lot of good reference material in these forums to create the following script. Now that I know it functions properly from the MyGroovy console, I need to remove stuff to make it work as a post transition function.
The problem is, I'm unfamiliar with the objects available at that time. My script is complicated because I had to emulate the workflow transition environment. I think I can remove the stuff I used for emulation: usermanager stuff, getprojectbykey, and getissuebycurrentkey. I'm just not sure how to begin.
The script is designed to get the users from a role and add them to a Cc field upon ticket creation. The need for this is based on project admins not having the ability to customize custom field contexts in our current version 7.10.2 and a great multitude of tickets are generated with requests for customizing this field. I could find no other cheap solutions.
Suggestions and comments from the community are greatly appreciated.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.event.type.EventDispatchOption
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
UserManager userManager = ComponentAccessor.getUserManager()
ProjectManager projectManager = ComponentAccessor.getProjectManager()
ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
ProjectRole ccRole = projectRoleManager.getProjectRole("Default Cc")
MutableIssue issue = (MutableIssue) issueManager.getIssueByCurrentKey("TEST-123")
CustomField customField_CC = customFieldManager.getCustomFieldObject(10400)
List<ApplicationUser> userList = new ArrayList<>();
for (ApplicationUser userKey : (List<ApplicationUser>) issue.getCustomFieldValue(customField_CC))
{
userList.add(userKey)
}
Project project = projectManager.getProjectByCurrentKey("TEST")
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(ccRole, project)
for (ApplicationUser userKey : actors.getUsers())
{
userList.add(userKey)
}
userList = userList.unique()
ApplicationUser currentUser = userManager.getUserByName("johnsmith")
issue.setCustomFieldValue(customField_CC, userList);
issueManager.updateIssue(currentUser,issue,EventDispatchOption.ISSUE_UPDATED,false)
return userList