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 Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs 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
Diagnosis
NA
Cause
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.
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
1
2
3
4
{{issue.comments.last.author}} added a new comment:
{{issue.comments.last.body.html.replaceAll("/jsm/secure/attachment/", "/jsm/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:
Was this helpful?