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

0 votes
Accepted answer

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 Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

302 views 0 1
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