Scriptrunner: Set userfield

Andrea Hakim July 21, 2017

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

0 votes
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2017

Hello Andrea.

This seems odd, do the logs provide any information?

Cheers!

DYelamos

Andrea Hakim July 26, 2017

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

Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2017

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
TAGS
AUG Leaders

Atlassian Community Events