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

Groovy: Check if user is in group

Georgiy Senenkov Sep 11, 2012


My JIRA setup contains custom field "Team". Also user groups have been created and their names exactly corresponding "Team" values. Based on this assumption I need to check whether the issue assignee belongs to the user group.

I made groovy script

MutableIssue issue = issue
componentManager = ComponentManager.instance
customFieldManager = componentManager.getCustomFieldManager()
userUtil = componentManager.getUserUtil()

cfTeam = customFieldManager.getCustomFieldObjectByName("Team")
teamUserGroup = issue.getCustomFieldValue(cfTeam)
assigneeUserName = issue.getAssigneeUser().getName()

if (userUtil.getGroupNamesForUser(assigneeUserName).contains("TEAM1")){
	System.out.println("Assignee is in the Team Group! " )

and it works well if Team is exclitely mentioned as "TEAM1", but if I use value taken from custom field, i.e.

if (userUtil.getGroupNamesForUser(assigneeUserName).contains(teamUserGroup))

it returns the error

javax.script.ScriptException: javax.script.ScriptException: java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.issue.customfields.option.Option

I think solution should be trivial, but didn't manage to resolve it.

Could you please help?

Best regards, Georgiy

2 answers

1 accepted

1 vote
Answer accepted
Jobin Kuruvilla [Go2Group] Community Leader Sep 11, 2012


teamUserGroup = issue.getCustomFieldValue(cfTeam)


teamUserGroup = issue.getCustomFieldValue(cfTeam).toString();

Do null checks and stuff.

Jobin Kuruvilla [Go2Group] Community Leader Sep 11, 2012

toString or getValue as Henning suggested. Just saw it!

Georgiy Senenkov Sep 12, 2012

Thank you! It works!

1 vote
Henning Tietgens Sep 11, 2012
Is the CF a Select List? You get an "Option" as result of getCustomFieldValue(). You have to use getValue() on the Option object to get the String representation.
Georgiy Senenkov Sep 12, 2012

Oh, that was mistake.

I used

teamUserGroup = issue.getCustomFieldValue(cfTeam).toString();

and it works!!!

Thank you very much!

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

707 views 0 4
Join discussion

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