-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c4ccf7
commit 6b330c1
Showing
6 changed files
with
86 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* @name addPrimaryUserAsParticipant.groovy | ||
* @type Script Post Function | ||
* @brief Adds the user in custom field "Primary User" to the field "Request Participants" | ||
*/ | ||
|
||
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.IssueManager | ||
import java.util.ArrayList | ||
import com.atlassian.jira.user.ApplicationUser | ||
import org.apache.log4j.Logger | ||
|
||
def log = Logger.getLogger("com.acme.XXX") | ||
|
||
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() | ||
def REQUEST_PARTICIPANTS_FIELD = "customfield_10600" | ||
def PRIMARY_USER_FIELD = "customfield_10913" | ||
|
||
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() | ||
IssueManager issueManager = ComponentAccessor.getIssueManager() | ||
MutableIssue issue = issue // FOR TESTING IN CONSOLE replace `issue` with `issueManager.getIssueObject("{issuekey}")` | ||
|
||
/* Get field objects */ | ||
def requestParticipantsField = customFieldManager.getCustomFieldObject(REQUEST_PARTICIPANTS_FIELD) | ||
def primaryUserField = customFieldManager.getCustomFieldObject(PRIMARY_USER_FIELD) | ||
|
||
/* Get Primary User */ | ||
ApplicationUser primaryUser = issue.getCustomFieldValue(primaryUserField) as ApplicationUser | ||
|
||
if (primaryUser) { | ||
|
||
/* Create an empty arraylist and add Primary User */ | ||
ArrayList<ApplicationUser> participants = [] | ||
participants.add(primaryUser) | ||
|
||
/* Assign the arraylist to the Request Participants field */ | ||
issue.setCustomFieldValue(requestParticipantsField, participants) | ||
|
||
/* Store to database. */ | ||
try { | ||
issueManager.updateIssue( | ||
currentUser, | ||
issue, | ||
EventDispatchOption.ISSUE_UPDATED, | ||
false | ||
) | ||
} catch (Exception e) { | ||
log.debug "Exception: " + e | ||
} | ||
|
||
} else { | ||
log.debug "No Primary User specified." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters