Jira 7.2.7
Script Runner 5.3.9
I've got a requirement to update a custom user selection field value with a set userid when an issue is cloned. I've figured out the detecting a clone part (a different post helped me out on that). My issue right now is that I can't get this field to update. It appears to be changed, but the value I submit does not get written to the database.
Right now I've got a very dumbed down script that look like this
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("mwilson")
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11500");
issue.setCustomFieldValue(cf, user)
This generates no errors, but appears to do nothing. "customfield_11500" is a single user selection field.
If I modify the code like this to just update a custom single line text field, it works fine.
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11502");
issue.setCustomFieldValue(cf, "mwilson")
So obviously something special is required here for a user type field. Any ideas what I'm going wrong here?
Kindly have a look at my article:
You should add something like this to the end of your script:
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
First off, nice article. Thank you for sharing it!
Your suggestion worked! I had to make one other change though.
I updated my code as you suggested (new lines in bold)
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("mwilson")
def lUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11500");
issue.setCustomFieldValue(cf, user)
ComponentAccessor.getIssueManager().updateIssue(lUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
I also had to move my post script function down so it fired after the "Creates the issue originally" step. I see this does give me multiple updates in my ticket history, but I'm not concerned about that...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
None of the above methods worked for me, perhaps because I'm on a newer version of Jira Server 8.5.1. This worked for me setting a single user field called "Approver" with the current user.
import com.atlassian.jira.component.ComponentAccessor
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find { it.name == "Approver" }
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setCustomFieldValue(customField, currentUser)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Matt,
If you are ok with just the name of the user, try converting the user value to string like,
issue.setCustomFieldValue(cf, user.toString())
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.
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.