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

Remove agents from the "Request participants" field automatically using Automation For Jira.

This workaround is intended for people who would like that whenever an agent is added to the “Request participants” field, the user is removed automatically. When a customer adds an agent to their request as a participant, that agent is subsequently treated as a customer for the purposes of triggering SLAs, automation rules, or notifications. In most cases, this is not a desired scenario, so we will use this workaround to prevent this.

We will make use of Automation For Jira, Rest API, and Web Requests to accomplish this. I will explain the needed steps below:

1. Set up an API token for your site that will be used in your automation.

  • Initially you will need an API Token created for authentication, to send a web request to an API endpoint using your automation rule. In case you don't have any API token configured, you may check the needed steps in this document
    :warning: Once created you won't be able to see it again, so I'd advise copying the API token string to another location, we will need this later.

  • With the above token created, you will need to encode it to the authorization string. In the 2nd step from this community post, there's a detailed guide on how to do so, but basically, we can make this through any online tool like Base64 encode or you can use a terminal session and execute the following:

    $ echo -n "<email@example.com>:<YOUR_TOKEN_HERE>" | base64
    You would need to replace <email@example.com> with your user’s email address and <YOUR_TOKEN_HERE> for the API token you generated at the previous step, separated by the “:” character and between the ““ characters. Once you execute this command, please save the generated string to use later.

2. Create your automation rule.

Go to your Project Settings > Automation and start a new rule using the following components:

  • We will use the "Field value changed" trigger.

    • In this case we will monitor changes in the “Request participants” field for “Value added” change type.

  • For the 2nd component, we will use an "Advanced branching" component, we will iterate on every user's account ID that are listed in the "Request participants" field.

    • We will use the following smart value.

    • {{Request participants.accountId}}

      branch.png

  • Inside the “Advanced branching” component we will use the “Send web request” action component. For every user in the “Request participants” field, we will get the groups that the user is a member. Here it gets a bit tricky, you will have to configure it with the following values:
    Web request URL:

    {{baseUrl}}/rest/api/2/user?accountId={{remove}}&expand=groups

    You may find additional details for this API endpoint in this link.

    Headers:

    Accept: application/json
    Authorization: Basic <base64-token> 

    :warning: Remember to replace <base64-token> by your generated base64 encoded string at the 1st step from this post.
    HTTP Method:

    GET

    Web request body:

    Empty

    :warning: And Check the "Delay execution of subsequent rule actions until we've received a response for this web request" checkbox.
    web-request.png

  • Once we have the response from the previous web request, we will use the an "Advanced condition" to check if the response contains a specific group.

    • In the “First value” we will use the following smart value:

    • {{webResponse.body.groups.items.name}}
    • For “Condition” we will use "contains".

    • In the “Second value” field, we will set any group name that we would like to identify our agents. In this example, I will use the group that provides default access to the JSM product ("jira-servicemanagement-users-<instance>"), but you may use any group that best suit your needs.
      advanced-compare.png

  • Finally, we will use the "Edit issue" action, to remove any user that matches the above condition (is a member of the group) from the "Request participants" field. For this, we will use the "More options" > "Additional fields" section from the action.

    • In the “Additional fields” section, we will use the following JSON:

      {
      	"update": {
      		"Request participants" : [ {
      			"remove": {
      				"id":"{{remove}}"
      			}
      		}]
      	}
      }

      edit-issue.png

After setting up your automation rule, you should have something similar to this:

automation-rule.png

3 comments

Lucas Silva
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 8, 2023

Awesome!

Great article, @Rodrigo Henrique!

Like Rodrigo Henrique likes this
Masayuki Abe
Contributor
September 11, 2023

It would be fantastic if we could add the user that has been removed from the request participants to the watchers.

Natalya Ozhigova
Contributor
September 12, 2023

Great! But did you check the case when the user adds more than one agent? 

I would like to notice that in such configuration it is important to check the checkbox to allow the rule triggers the itself. The branch makes actions at the same time, and sometimes the changes overlap each other. The another option is to create a second rule as a loop, but it is a more complicated and in this case unnecessarily.

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events