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

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
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 Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

165 views 0 4
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