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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

254 views 0 6
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