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

HowTo: change Group Picker (multiple groups) with scriptrunner / post-function

Ewald_Ninaus October 16, 2015

 want to set a "Group Picker (multiple groups)" with a post-function. Maybe you can give me a hint...

 

If a "customer" makes a new Task, the Group Picker "Security Level Group" should be automatically filled with the existing Group "customer".
the following if/else works, and I can set the Description depending on customer yes/no, but i have no Chance to set the customer-group into my userSecGrp.
I also did not find anything in the Internet that could help me.
def userSecGrp = customFieldManager.getCustomFieldObjectByName("Security Level Group")
def groupManager = ComponentAccessor.getGroupManager()
 if (groupManager.isUserInGroup(issue.reporter?.name, 'customer') )

{

 issue.setDescription("A generated description for extern customer")

def group = groupManager.getGroup("customer")

def groupObj = groupManager.getGroupObject('customer')

// issue.setCustomFieldValue(userSecGrp, group)

//issue.setCustomFieldValue(userSecGrp, group)

//issue.setCustomFieldValue(userSecGrp, groupManager.getGroupObject('customer'))

//issue.setCustomFieldValue(userSecGrp, userUtil.getUserByName("xy")) } 

else

{

 system fields issue.setDescription("A generated description for non-customer")

 } 

If i activate one of the setCustomFieldValue, I only get the message that something is not compatible to my jira Version.
So the question is: How to setCustomFieldValue for a Group Picker to a Group? or GroupObject...

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 20, 2015

The following code works for me to set the value of single and multigroup custom fields:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()

def multiGroupCf = customFieldManager.getCustomFieldObjectByName("multigrouppicker")
def singleGroupCf = customFieldManager.getCustomFieldObjectByName("GroupPicker")

def group = groupManager.getGroup("jira-developers")

issue.setCustomFieldValue(multiGroupCf, [group])
issue.setCustomFieldValue(singleGroupCf, [group])

You get the error you're receiving when passing a single group, rather than a collection.

Tim S_ June 12, 2017

Hi,

I try to set an MultiGroupPicker custom field with multiple groups. The setting with 'setCustomFieldValue' works fine.

...
List<Group> accessGroups = (List<Group>) mutableIssue.getCustomFieldValue(multiGroupCf);
if(accessGroups != null)
{
  accessGroups.add(groupManager.getGroupObject(it));
  //set custom field
  mutableIssue.setCustomFieldValue(multiGroupCf, [accessGroups]);
}
...

 

But if I update the issue with

    ComponentAccessor.getIssueManager().updateIssue(currentUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false);

I get the following error

 

...
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.atlassian.crowd.embedded.api.Group
...

 

Maybe you ca help me with this.

0 votes
Ewald_Ninaus October 20, 2015

A thousand thanks!

the "[ ]" was the missing thing in my code.

 

now it work's for me!

TAGS
AUG Leaders

Atlassian Community Events