Error rendering macro 'redirect'

Invalid URL: "JIRAKB:(Archived) Add request participants automatically when creating an issue in Jira server". Please provide a valid URL to redirect to.

This fix requires a third party plugin, which is not supported by Atlassian. See the Script Runner page on the marketplace for support information on this plugin.

Purpose

When creating an issue through the Customer Portal, it's possible to 'Add People' who are considered a participant on the issue, as detailed in Adding people to participate in requests. This KB details how to go about automatically adding users as part creating an issue.

Solution

The below workaround requires an third-party plugin supported by a separate vendor to Atlassian, and also will need to be changed every time JIRA is upgraded as code can change behind the scenes. If you require assistance with changes to this code please raise a question on Atlassian Answers.

  1. Install to Script Runner plugin. This is a paid for plugin supported by a separate vendor.
  2. Edit the workflow and modify the 'Create Issue ' transition as per Configuring Workflow.
  3. Add a scripted post function as per Script Runner Post-Functions.
  4. Use the following Java code, replacing customfield_10001 with the appropriate custom field ID of the Participants field, and the users with the appropriate usernames:

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.user.ApplicationUser
    import java.util.ArrayList
    import com.atlassian.jira.issue.ModifiedValue
    import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
    import com.atlassian.jira.issue.MutableIssue
    import com.atlassian.jira.issue.IssueManager
    import com.atlassian.jira.issue.index.IssueIndexManager
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
    def userManager = ComponentAccessor.getUserUtil()
    def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001")
    def issueManager = ComponentAccessor.getIssueManager()
    def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    def issueIndexManager = ComponentAccessor.getIssueIndexManager()
    def getUsersAsArray = {
        def users = ["ben", "steve"]
        ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>()
        users.each {
            def user = userManager.getUserByName(it)
            if(user)
            { userList.add(user) }
        }
        return userList
    }
    MutableIssue myIssue = issue
    ArrayList<ApplicationUser> applicationUsers = getUsersAsArray()
    myIssue.setCustomFieldValue(requestParticipantsField, applicationUsers)


  5. Test by creating an issue.

Help us improve!
  • No labels

1 Comment

  1. Dave C updated the script to pickup users from a group instead of hard-coded in the script.

     

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.user.ApplicationUser
    import java.util.ArrayList
    import com.atlassian.jira.issue.ModifiedValue
    import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
    import com.atlassian.jira.issue.MutableIssue
    import com.atlassian.jira.issue.IssueManager
    import com.atlassian.jira.issue.index.IssueIndexManager
    import com.atlassian.jira.security.groups.GroupManager
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
    def userManager = ComponentAccessor.getUserUtil()
    def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001")
    def groupToAdd = "people-request-participants"
    def issueManager = ComponentAccessor.getIssueManager()
    def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    def issueIndexManager = ComponentAccessor.getIssueIndexManager()                                                    
    def groupManager = ComponentAccessor.getGroupManager()
    def getUsersAsArray = {
        ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>()
        def requestParticipantsGroup = groupManager.getGroup(groupToAdd)
        if(requestParticipantsGroup){
            def users = groupManager.getUserNamesInGroup(requestParticipantsGroup)
            users.each {
                def user = userManager.getUserByName(it)
                if(user){
                    userList.add(user)
                }
            }
        }
        return userList
    }
    MutableIssue myIssue = issue
    ArrayList<ApplicationUser> applicationUsers = getUsersAsArray()
    if(applicationUsers){
        myIssue.setCustomFieldValue(requestParticipantsField, applicationUsers)
    }