Scriptrunner: Set userfield

I realize this topic has been posted before but I've spent quite a bit of time searching, and I've tried multiple methods to populate a user field and I'm still unsuccessful.  

Just to isolate where I'm having difficulty, I have a user id (which will be set to a variable) and I want to use that value to populate a single user custom field (Division Lead)

I'm using JIRA 7.1.2, and the Script Console.  The result = CarlA(carla), but the Division Lead doesn't get updated.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser


def issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueObject("TEST-67")


CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def dl = customFieldManager.getCustomFieldObjectByName("Division Lead")

ApplicationUser user = ComponentAccessor.getUserManager().getUserByName('carla')
issue.setCustomFieldValue(dl, user)

 

 

1 answer

Hello Andrea.

This seems odd, do the logs provide any information?

Cheers!

DYelamos

I either don't have any logs to review or I'm looking in the wrong place.  What log files should I be reviewing?

Thanks, Andrea

You shuold look for the JIRA logs using the SR log viewer

Can you replace your script with this and then check the logs?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser

def issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueObject("TEST-67")
log.debug "BEGIN DEBUGGER: ISSUE " + issue

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def dl = customFieldManager.getCustomFieldObjectByName("Division Lead")
log.debug "DEBUGGER CUSTOMFIELDS " + dl
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName('carla')
issue.setCustomFieldValue(dl, user)

 See the lines with BEGIN DEBUGGER and DEBUGGER CUSTOMFIELDS and copy paste them to me.

Cheers!

Dyelamos

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

169 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you