Dear community,
I’m facing the following issue in Jira Data Center (Service Desk):
I would like approvers to receive an email notification when the issue transitions to the approval status. However, the email should include additional non-default fields (for example, custom fields that are not normally visible in the default approval notification).
At the same time, it is important that the email still contains the built-in Approve and Decline buttons available in the standard Jira approval emails.
Is it possible to create such a customized approval email using native Jira functionality or ScriptRunner, while preserving the Approve and Decline buttons?
Hello @Asya , this can partially be done when you go to Space Settings -> Notifications -> Customer notifications -> Approval required
From the picture you can see that there isn't an option for adding your custom field. Even if you try with options like ${issue.customfield_XXXX} it won't present the value itself.
Thank you Nikola, Do you have any info how I can use ScriptRunner in this case?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you checked the article: https://community.atlassian.com/forums/Jira-Service-Management-articles/JSM-Approvals-by-Email-with-a-work-around/ba-p/1696674#M699 by @John Funk ? @Marc -Devoteam- also mentioned this article.
For the ScriptRunner, you would use a listener on the even Work item updated. Replace the values from the script to match your custom field ID. To find your custom field ID, you would need to get to Context and values and in your URL you will see the ID.
// Event: Work Item Updated / Issue Updated
def eventIssue = Issues.getByKey(issue.key as String)
// Guard: only run in your JSM project
if (eventIssue.projectObject.key != "SD") {
return
}
// Guard: only run in approval status
if (eventIssue.status.name != "Waiting for approval") {
return
}
// Read your custom field by name
def businessJustification = eventIssue.getCustomFieldValue("Business Justification")?.toString()
if (!businessJustification) {
logger.info("No Business Justification value, skipping notification")
return
}
// Read approvers field
// Replace with your actual approver custom field name if needed
def approvers = eventIssue.getCustomFieldValue("Approvers")
if (!approvers || approvers.isEmpty()) {
logger.info("No approvers found, skipping notification")
return
}
// Optional: avoid duplicate sends
def alreadySent = eventIssue.getCustomFieldValue("Approval Reminder Sent")
if (alreadySent == "Yes") {
logger.info("Reminder already sent, skipping")
return
}
// Build recipient list from accountIds
def accountIds = approvers.collect { it.accountId }.findAll { it }
// Build notification payload for Jira notify API
def payload = [
subject: "Approval needed for ${eventIssue.key}: ${eventIssue.summary}",
textBody: """Approval is required for ${eventIssue.key}
Summary: ${eventIssue.summary}
Business Justification: ${businessJustification}
Open request: ${baseUrl}/browse/${eventIssue.key}
""",
htmlBody: """
<p>Approval is required for <strong>${eventIssue.key}</strong></p>
<p><strong>Summary:</strong> ${eventIssue.summary}</p>
<p><strong>Business Justification:</strong> ${businessJustification}</p>
<p><a href="${baseUrl}/browse/${eventIssue.key}">Open request</a></p>
""",
to: [
users: accountIds.collect { [accountId: it] }
]
]
// Send notification
def resp = post("/rest/api/3/issue/${eventIssue.key}/notify")
.header("Content-Type", "application/json")
.body(payload)
.asString()
if (resp.status >= 200 && resp.status < 300) {
logger.info("Notification sent for ${eventIssue.key}")
// Mark as sent so it does not resend
eventIssue.update {
setCustomFieldValue("Approval Reminder Sent", "Yes")
}
} else {
logger.error("Notify API failed: ${resp.status} ${resp.body}")
}
Replace
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Asya,
Prior to JSM Cloud incorporating this as a normal function (not sure if DC has done that not, but check that first), I created this article on how to do it with an automation rule. You can modify as needed to fit your use case/tools.
|
|
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI @Asya
Yes this is possible.
In the project settings of the JSM projects, go to the section "Customer notifications", choose the Approval required notification and edit the content of the notification,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Marc
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Why would you need scriptrunner?
You can do this on using automation, see this article: https://community.atlassian.com/forums/Jira-Service-Management-articles/JSM-Approvals-by-Email-with-a-work-around/ba-p/1696674#M699
You might be able to duplicate this in Scriptrunner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.