/
Comment linked issues
Comment linked issues
Let's add the same comment to the linked issue.
Assumption
In our TESTB project, we got two issues linked together with inward "is caused by". When we comment on the issue it shall add a comment to the linked issue as well.
Steps
Part 1 - Get the linked issue
- Create a new Action by clicking CREATE button
- Enter a name: Get Linked Issue and click CREATE
- Select Method: GET and URL: <your_base_url>/rest/api/2/issue/{{issue.key}}?fields=issuelinks
From the Atlassian REST API we can read that to fetch issue links by getting the issue JSON and further filter it by fields=issuelinks. call GET /rest/api/2/issue/{{issue.key}}?fields=issuelinks - Select Authentication method: Basic Auth, specify a user with comment and browse permissions
- Add request headers, key: Content-Type with value application/json
- Click Triggers tab
- Select ISSUE COMMENTED event
- On JQL Condition. When to execute the event(s) write project = TESTB AND issueLinkType = "is caused by" to limit the trigger to the TESTB project and only the direction of "is caused by".
- Click SAVE
- (Optional) Click Test button (no issue key is needed) to and click Send, Then go Log Tab.
Each result will have a response like the one below:
{ "expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations", "id": "12837", "self": "https://support.rixter.se/rest/api/2/issue/12837", "key": "TESTB-7", "fields": { "issuelinks": [ { "id": "11102", "self": "https://support.rixter.se/rest/api/2/issueLink/11102", "type": { "id": "10300", "name": "Problem/Incident", "inward": "is caused by", "outward": "causes", "self": "https://support.rixter.se/rest/api/2/issueLinkType/10300" }, "inwardIssue": { "id": "12839", "key": "TESTB-8", "self": "https://support.rixter.se/rest/api/2/issue/12839", "fields": { "summary": "Linked issue test", "status": { "self": "https://support.rixter.se/rest/api/2/status/10003", "description": "", "iconUrl": "https://support.rixter.se/", "name": "To Do", "id": "10003", "statusCategory": { "self": "https://support.rixter.se/rest/api/2/statuscategory/2", "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "priority": { "self": "https://support.rixter.se/rest/api/2/priority/4", "iconUrl": "https://support.rixter.se/images/icons/priorities/low.svg", "name": "Low", "id": "4" }, "issuetype": { "self": "https://support.rixter.se/rest/api/2/issuetype/10002", "id": "10002", "description": "A task that needs to be done.", "iconUrl": "https://support.rixter.se/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype", "name": "Task", "subtask": false, "avatarId": 10318 } } } } ] } }
Part 2 - Get the last comment (this step will in the future be replaced by a smart function)
- Create a new Action by clicking CREATE button
- Enter a name: Get Last Comment and click CREATE
- Select Method: GET and URL: <your_base_url>/rest/api/2/issue/{{issue.key}}/comment
from the Atlassian REST API we can read that to fetch issue links by getting the issue JSON and further filter it by fields=issuelinks. call GET /rest/api/2/issue/{issueIdOrKey}/comment - A new section called Variables is now displayed. On this section enter the
- Variable name: inwardIssue and the JSON Path: $.fields.issueLinks[0].inwardIssue.key
The JSON path will return a variable with the value of the last comment
- Variable name: inwardIssue and the JSON Path: $.fields.issueLinks[0].inwardIssue.key
- Select Authentication method: Basic Auth, specify a user with browse permissions
- Add request headers, key: Content-Type with value application/json
- Click SAVE
- (Optional) Click Test button (no issue key is needed) to and click Send, Then go Log Tab.
Part 3 - Add the last comment to linked issue
- Create a new Action by clicking CREATE button
Enter a name: Comment linked issue and CREATE
note on the Select parent action choose to Get Last Comment which we created in part 1 and click
This will create a chained action that will be triggered directly after the response from the parent action is received. The response will be used as input variables this call using JSON Path expressions.- A new section called Variables is now displayed. On this section enter:
- Variable name: lastComment and the JSON Path: $.comments[-1:].body
The JSON path will return a variable with the value of the linked issue key.
- Variable name: lastComment and the JSON Path: $.comments[-1:].body
- Select Method: POST and URL: <your_base_url>/rest/api/2/issue/{{inwardIssue}}/comment
note that we now use the inwardIssue in the URL that we post to.
From the Atlassian REST API we can read to comment on an issue we need to call POST /rest/api/2/issue/{{issue.key}}/comment - Select Authentication method: Basic Auth, specify a user that has comment permission in the project
- Add request headers, key: Content-Type with value application/json
On the Body section add the following
{ "body":"{{lastComment}}" }
- Click SAVE
- (Optional) Click Test button, Issue Key needs to be provided and click Send, Then go Log Tab.
, multiple selections available,
Related content
Comment Issue
Comment Issue
More like this
Issue Events samples
Issue Events samples
More like this
Create an Object on transition
Create an Object on transition
More like this
Append severity to a comment when changed
Append severity to a comment when changed
More like this
Add project role members as watchers on Create
Add project role members as watchers on Create
More like this
Create a user and find a user
Create a user and find a user
More like this