How to query a Group picker customfield ?

hi guru,

Need help urgently on trying to query a GroupPicker customfield. I wrote the following code in the script console using the scriptrunner groovy script for the query but instead of returning the group_name, it is returning a class like object  "com.atlassian.crowd.embedded.impl.ImmutableGroup@c53".

 

Any ideas what is wrong with my code ? Thanks in advance.

// issue key : "RMD-2"

// group picker customfield : "customfield_10204"

//###########################################

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.user.ApplicationUser

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("RMD-2")
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10204")
def abc= issue.getCustomFieldValue(customField).toString()

if (abc==null) {return "fish !"} else {return "1. => "+abc + "    from => "+customField.toString()}

//
// returns: 1. => [com.atlassian.crowd.embedded.impl.ImmutableGroup@c53] from => amt_to_WIP
//

//###########################################

 

1 answer

Thanks to guru Ari Hermawan who helped me to fixed the code with the following additional lines.

 

if ((issue) && (customField)) { // check both Issue and Field exist
def customFieldVal = issue.getCustomFieldValue(customField)

if (customFieldVal) { // if object exists
if (customFieldVal instanceof java.util.Collection) { // if it's a Collection
abc=customFieldVal.getAt(0).getName() // get the first element's Name
}
else abc=customFieldVal.toString() // else it's a string
}
else return "NOT_FOUND"
}

return abc

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 21, 2018 in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

1,191 views 10 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