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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

365 views 0 6
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