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

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 Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

380 views 3 17
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