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.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// a user custom field
def 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes is's possible. You can use script above with some modification.
You need getCustomFieldValue() method istead of getAssignee()
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// a user custom field
def 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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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)
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is static type checking error you can ignore it. It will work :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Markov , code does not working, it returns the error, I am trying to copy the current log in user to a single user pick custom field. How can I do that? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
def cfMultiSelectUser = customFieldManager.getCustomFieldObjectByName("CC")
def cfMultiSelectUserValue = issue.getCustomFieldValue(cfMultiSelectUser)
((java.util.List)cfMultiSelectUserValue).add(currentUser)
cfMultiSelectUser.updateValue(null, issue, new ModifiedValue(cfMultiSelectUserValue, cfMultiSelectUserValue),changeHolder);
The above code should have worked.
Regards,
MG
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nic, this is what I tried, and it's not successful:
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userUtil = ComponentAccessor.getUserUtil()
// a user custom field
def userCf = customFieldManager.getCustomFieldObjectByName("Responsible User(s)")
issue.setCustomFieldValue(userCf, issue.get.Assignee())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is the field a multi-user picker? The name suggests it might be?
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.
Ok, so the last paragraph applies, you need to treat it as a list.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This can be done using script runner or jira suite utilities plugins Suzanne.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.