Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Cannot retrieve custom field value from user picker type

I been having a hard time finding out why this is not working. I am trying to get the custom field value of "Affected User" which is a user picker field.

Here's my groovy script.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager

def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = componentManager.getCustomFieldManager()

def type = issue.getIssueTypeObject().getName()
def summary = issue.getSummary()
def cf1 = customFieldManager.getCustomFieldObjectByName("Affected User")
def user = issue.getCustomFieldValue(cf1)

The type and summary works fine when I run it in the script runner with the following code:

def componentManager = ComponentManager.getInstance()
def issue = componentManager.getIssueManager().getIssueObject("ACR-42")

I get the following results with script runner:

com.atlassian.crowd.embedded.ofbiz.OfBizUser@c2c49b46

Any idea why I can't actually retrieve the user name?

2 answers

1 accepted

3 votes
Answer accepted

The actual user name (not the User object) should be:

issue.getCustomFieldValue(cf1).name

Thanks. That worked. Always missing something simple.

hi @Eugene Domingo you have used this script for Listener or Behavior? 

Because when i am using it in listener , i am getting error for static type checking error "def issue = customFieldManager.getIssueManager().getIssueObject("ACR-42")"

below i have pasted the code.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.issue.customfields.manager.OptionsManager

def componentManager = ComponentManager.getInstance()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
//IssueManager issueManager = ComponentAccessor.getIssueManager();


def issue = customFieldManager.getIssueManager().getIssueObject("ACR-42")


def type = issue.getIssueTypeObject().getName()
def summary = issue.getSummary()
def cf1 = customFieldManager.getCustomFieldObjectByName("Impacted Application/s")
def user = issue.getCustomFieldValue(cf1).getName()

 

 

Regards

Manas

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

290 views 2 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you