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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,459,266
Community Members
 
Community Events
176
Community Groups

Script Listener: add group to custom field in case a specified group is also present

Hello community,

for a rather complex use case I am looking for a solution utilizing ScriptRunner (v. 5.4.30 on Jira 7.10) to add a existing group in Jira to a custom field given the circumstance that another existing group is already put to the custom field (type group picker, multiple).

For example: as soon as the group "accounting" is put to custom field, manually by a user, the group "quality_managers" instantly (therefore listener, I thought) also should be put in there.

Is this something that could be done at all?

Thanks in advance,
Cheers,
Birgit

1 answer

1 accepted

0 votes
Answer accepted

This is untested but should work (only in the edit event, if the user changes the customField from a transition screen it shouldnt work unless you add the transition event in the event list of the listener)

You have to add the edit event in the event select list from the listener.

 

/*
* Add the group "quality_managers" to the multiGroupPicker customField "Multi Group Picker" when this customField is edited
* and added the group "accounting"
*/

import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.user.ApplicationUser
import org.ofbiz.core.entity.GenericValue

MutableIssue issue = event.issue as MutableIssue

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
GroupManager groupManager = ComponentAccessor.getGroupManager()

CustomField cfMultiGroupPicker = customFieldManager.getCustomFieldObject(11111L) // Change whit your CustomField ID
List<Group> groupPickerValue = issue.getCustomFieldValue(cfMultiGroupPicker) as List<Group>
Group qualityManagersGroup = groupManager.getGroup("quality_managers")
Group accountingGroup = groupManager.getGroup("accounting")

GenericValue changeLogs = event.getChangeLog()
ArrayList<ChangeHistoryItem> changedItem = changeHistoryManager.getAllChangeItems(issue).findAll {
it.changeGroupId == changeLogs.id
}
if (changedItem.field.contains(cfMultiGroupPicker.name.toLowerCase()) && groupPickerValue.contains(accountingGroup)) {

issue.setCustomFieldValue(cfMultiGroupPicker, [groupPickerValue, qualityManagersGroup])

}

if (issue.getModifiedFields()) {

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
ComponentAccessor.getComponent(IssueIndexingService).reIndex(issue)

}

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events