Automation For Jira: How to write a rule that will send an email including the customer facing URL of the attachments
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The purpose of this KB article is to describe how to write an automation rule that will send an email to JSM (Jira Service Management) customers that will:
- include the last comment added to a JSM request
- convert the attachment URLs from the Jira (agent) facing URLs into the Customer facing URLS
Problem
When using the smart value {{comment.body.html}} to include the last comment added to a request, if the comment contains attachments, the URLs of these attachments will be the internal Jira URLs and not the Customer facing URL. As a result, this smart value cannot be used as it is, since the customer who receives the email will not be able to open the attachment because the internal Jira URL of attachments can only be opened by Jira users with a license.
Let's assume that the attachment file name is screenshot-1.png, and that it was attached to a Jira issue which Database ID is 10100 (not to be confused with the issue key). In this case:
the Jira facing URL of this attachment will be:
<JIRA_BASE_URL>/secure/attachment/10101/10101_screenshot-1.png
the Customer facing URL of this attachment will be
<JIRA_BASE_URL>/secure/servicedesk/customershim/secure/attachment/10101/10101_screenshot-1.png?fromIssue=10100
The automation rule described in this article will make the conversion from the Jira facing URL into the Customer facing URL of all attachments included in the comment.
Environment
- Jira Service Management Server/Data Center on any version from 4.0.0
- Automation For Jira on any version from 9.0.0
Solution
Rule configuration details
The rule needs to be configured as described below:
- Add the Issue Commented trigger
- Add the Create Variable action with the parameters below:
- Variable name: issueID
Smart value:
{{issue.id}}
- Add the Send Email action with the parameters below:
- To: add the recipient of your choice
- Subject: add the subject of your choice
Content: add the content below
{{issue.comments.last.author}} added a new comment: {{issue.comments.last.body.html.replaceAll("/secure/attachment/", "/servicedesk/customershim/secure/attachment/").replaceAll("(/secure/attachment/)(\\d{5})(.*?)\"","$1$2$3?fromIssue=IssueIdToReplace\"").replaceAll("IssueIdToReplace",issueID.trim())}}
Screenshot of the rule
The complete rule is illustrated in the screenshot below: