Setting values in Group Picker (single group)

Hi,
I have a custom field defined by the name "AG" (group picker[single group]). I want to set the values in it based on the groups i have like "Blocker","critical" etc. I tried the below code but getting exception while updating value in orderableField (last line).Can anyone please help me with this ? thanks

class IssueTypeListener extends AbstractIssueEventListener
{
Category log = Category.getInstance(IssueTypeListener.class)

@Override
void issueUpdated (IssueEvent event) {
log.setLevel(org.apache.log4j.Level.DEBUG)

def groupManager = ComponentAccessor.getGroupManager()
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

MutableIssue issue = event.issue
Project project = issue.getProjectObject()
IssueManager issueManager = componentManager.getIssueManager()

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
Group watcherGroup = componentManager.getUserUtil().getGroup("Blocker");
OrderableField orderableField = componentManager.getFieldManager().getOrderableField("AG")


List<Group> groupList = new ArrayList<Group>()
groupList.add(watcherGroup)
orderableField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(orderableField),groupList),changeHolder);


}
}

1 answer

1 accepted

This widget could not be displayed.

Below code would be helpful for setting the values (solved my problem)

class IssueTypeListener extends AbstractIssueEventListener
{
Category log = Category.getInstance(IssueTypeListener.class)

@Override
void issueUpdated (IssueEvent event) {
log.setLevel(org.apache.log4j.Level.DEBUG)

def groupManager = ComponentAccessor.getGroupManager()
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

MutableIssue issue = event.issue
Project project = issue.getProjectObject()
IssueManager issueManager = componentManager.getIssueManager()

def targetFieldName = "AG"
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();

Group watcherGroupforBlocker = componentManager.getUserUtil().getGroup("Blocker");
List<Group> groupListforBlocker = new ArrayList<Group>()
groupListforBlocker.add(watcherGroupforBlocker)
CustomField customFieldTarget = customFieldManager.getCustomFieldObjectByName (targetFieldName)

customFieldTarget.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customFieldTarget),groupListforBlocker), changeHolder)



}

}

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

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