How to Automatically Add Request Participants when Creating an Issue

Still need help?

The Atlassian Community is here for you.

Ask the community

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.

ScriptRunner 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.

 

JIRA Automation Solution

The below workaround requires the JIRA Automation Plugin

  1. Install the JIRA Automation Plugin
  2. Create a JQL Filter Trigger type with the Cron time that it should run and the JQL to search upon 
    (info) make sure to exclude tickets that already have Request Participants
  3. Choose Edit Issue Action
  4. Use the following line in the Edit Fields, replacing customfield_10200 with the appropriate custom field ID of the Participants field, and the users with the appropriate usernames:

    customfield_10200=admin, bcruz
  5. Test by creating an issue.

Last modified on Feb 26, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.