Add comments that match specific text to issues

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

Summary

When cloning an issue using Automations, comments from the trigger issue are not added to the cloned issue by default. These can be added after the issue is created using the Related issues branch, acting on the most recently created issue. However, there are times where not all comments are necessary to be added or scenarios where only specific comments are needed, such as those referencing particular teams, issue keys or words. This article aims to provide a solution to copy only those comments where a specific term is found.

Solution

In this scenario as we are updating a cloned issue therefore the trigger issue's comments can be accessed via the smart value {{triggerIssue}}. If you are working with an automation rule where you are acting on the same ticket, the smart value {{issue}} can be used to access comments. In the below example, we are searching for comments that contain issues pertaining to a specific project using the string ATP-. The smart value code for identifying those comments is:

{{triggerIssue.key}}

{{#triggerIssue.comments}}{{#if(exists(body.match(".*(ATP-).*")))}}
h4. {{author.displayName}} - {{created.mediumDateTime}}

{{body}}
{{/}}
{{/}}

The above uses formatting to help differentiate between comments and captures the comment author's display name as well as creation date. These are additional parameters and can be modified to suit your needs. A simple rule using the above snippet to copy comments to a cloned issue is seen in the screenshot below:

To test the above automation rule, we can use the following sample data where the expectation is only comments two and three will be copied as they contain the string we are looking for:

Once the automation rule has completed its run, based on the snippet and style chosen the final result will be:

Recommended resources to expand on the snippet are Jira Smart Jira smart values - Conditional logic and Jira Smart Values - Lists.

Last modified on Aug 28, 2023

Was this helpful?

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