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

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

491 views 3 18
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