We want to copy the assignee field to a custom field named 'Responsible User(s)'. Thanks
This can be done using script runner or jira suite utilities plugins Suzanne.
Yes, I plan to use script runner (I tagged issue with groovy-script-runner). I need help with my groovy script. I found similar posts where use case was to copy custom field to the assignee field. This is opposite... copy the assignee to custom field. Thanks
There's an example of setting lots of different field types over at https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html
On the section that sets the custom user-picker field, replace the "get user by name" function with a simple issue.getAssignee()
Although, I guess the field may be a multi-user picker. Assuming you really want to add the assignee, not replace another or destroy the current list, then you will want to get the current value of the customfield (which will be a collection or list), add to it, and then poke the collection back into the field.
Thanks Nic, this is what I tried, and it's not successful:
def customFieldManager = ComponentAccessor.getCustomFieldManager()def userUtil = ComponentAccessor.getUserUtil()
// a user custom fielddef userCf = customFieldManager.getCustomFieldObjectByName("Responsible User(s)")issue.setCustomFieldValue(userCf, issue.get.Assignee())
Is the field a multi-user picker? The name suggests it might be?
Yes, it is a multi-user picker.
Hello @Suzanne Seaton
I think you also need to save users that already exist in this field, so script should be like this
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.user.ApplicationUserdef customFieldManager = ComponentAccessor.getCustomFieldManager()// a user custom fielddef userCf = customFieldManager.getCustomFieldObjectByName("Responsible User(s)")List<ApplicationUser> userAlreadyInCustomField = issue.getCustomFieldValue(userCf)userAlreadyInCustomField.add(issue.getAssignee())issue.setCustomFieldValue(userCf, userAlreadyInCustomField)ComponentAccessor.getIssueManager().updateIssue(issue.getAssignee(), issue, EventDispatchOption.ISSUE_UPDATED, false)
HI @Mark Markov,
I want to set the approver name in to a custom field B (mulitple user picker).
Is this possible?
Thanks
Swarna
Yes is's possible. You can use script above with some modification.
You need getCustomFieldValue() method istead of getAssignee()
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.user.ApplicationUserdef customFieldManager = ComponentAccessor.getCustomFieldManager()// a user custom fielddef userCf = customFieldManager.getCustomFieldObjectByName("Responsible User(s)")def fieldtoCopy = customFieldManager.getCustomFieldObjectByName("FromFieldName")List<ApplicationUser> userAlreadyInCustomField = issue.getCustomFieldValue(userCf)userAlreadyInCustomField.add(issue.getCustomFieldValue(fieldtoCopy))issue.setCustomFieldValue(userCf, userAlreadyInCustomField)ComponentAccessor.getIssueManager().updateIssue(issue.getAssignee(), issue, EventDispatchOption.ISSUE_UPDATED, false)
@Mark Markov, thanks so much for trying to help me. Unfortunately I get the following error on line 10 which is your line that states 'List<Application User> userAlreadyInCustomField = issue.getCustomFieldValue(userCf)
Here is the error: cannot assign value of type java.lang.Object to variable of type java.util.List (ApplicationUser)
It looks like you're new here. Sign in or register to get started.