Hi There,
I'm trying to update custom field of type "User" and somehow it's not working for me and no errors either.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.fields.CustomField
CustomField itManager = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("IT Manager")
ApplicationUser itManagerUser = ComponentAccessor.getUserManager().getUserByName('popeye')
issue.setCustomFieldValue(itManager, itManagerUser);
I have found the workaround, just in case someone is looking for a similar solution.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def changeHolder = new DefaultIssueChangeHolder()
def itMgrField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("IT Manager")
def itMgrTargetFieldValue = issue.getCustomFieldValue(itMgrField)
ApplicationUser itMgrSourceFieldValue = ComponentAccessor.getUserManager().getUserByName('popeye')
itMgrField.updateValue(null, issue, new ModifiedValue(itMgrTargetFieldValue, itMgrSourceFieldValue),changeHolder)
Perhaps this is because setCustomFieldValue does NOT write your changes to the database and thus you have to update your issue after calling this method.
Try adding this to your code:
import com.atlassian.jira.issue.UpdateIssueRequest
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, UpdateIssueRequest.builder().build())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or put the post function first in the list of post functions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Ivan Tovbin and @Alexey Matveev for your prompt help here.
Unfortunately the above suggested workaround did not help me.
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.