I've built a workflow that has a transition from Closed to Closed called 'Clone' that creates a clone of the ticket into a different project and as a different issue type. I'm accomplishing this through a ScriptRunner post function, 'Clones an issue and links'. (In case it becomes important, it is currently the first post function in that transition.) Within the clone post function, I've set the new target project and target issue type. All gravy. ScriptRunner is the best.
Here is where I need help.
In the 'Additional issue actions' of that post function I want to replace the clone's Watcher field with users from a custom user-picker field (multi user field, called "Team"). This is important for us because there is often a dozen or more watchers on the original ticket whereas the clone will only have 2-3 watchers. And those populations don't overlap.
I don't know groovy, but I've used this community forum and lots of testing to hobble together enough so that this post function already (a) strips attachments, (b) gives the clone a name based on the original ticket, and (c) sets the clone's assignee based on a custom field ("Manager").
Any ideas on how to replace the Watchers field with information from the "Team" custom user-picker field? Thanks for any and all help!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.UpdateIssueRequest
// get required Managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// rename clone Summary field
issue.setSummary("Case" + " - " + issue.getSummary())
// remove attachments
checkAttachment = {attachment -> false}
// get a pointer to the user picker field and its value
def userCf = customFieldManager.getCustomFieldObjectByName("Manager")
def implUser = issue.getCustomFieldValue(userCf) as ApplicationUser
// if the user picker field is not null then set the assignee
if(implUser){
issue.setAssigneeId(implUser.username.toString())
}