Hello,
I'm currently working on a sending a custom email with the scriptrunner post function. I'm having some issues with the subject line of the email. Regardless of what I have tested the output into the email always contains two spaces before the text. I have tried using the subject template, setting the subject within the configurations, and even just adding plain text to the subject all resulting in multiple spaces added before the text.
Any and all help is appreciated.
Version: Jira server 9.4.5
Scriptrunner: 7.8.0
Subject Template Plain Text
Notification
Output: " Notification"
Subject Template:
<%// components
def notificationValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Notification Email")?.getValue(issue)?.toString()
def resolvedValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Resolve")?.getValue(issue)
def updateValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Business Notification Update Select")?.getValue(issue)?.toString()
def correctValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Business Notification Correction")?.getValue(issue)?.toString()
def summaryValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Notification Summary")?.getValue(issue)?.toString()
// Notification Mapping
def notificationMappings = [
"Proactive Maintenance":"Notification - {notificationValue} - {summaryValue}{status}"
]
// Status Conditions
def status = ""
if (correctValue == "Yes") {
status = " - CORRECTION"
} else if (resolvedValue != null) {
status = " - RESOLVED"
} else if (updateValue == "Yes" && resolvedValue == null) {
status = " - UPDATE"
}
// Retrieve the output string from the map
def outputString = notificationMappings.get(notificationValue)
if (outputString) {
// Replace placeholders with actual values
outputString = outputString.replace("{notificationValue}", notificationValue)
.replace("{summaryValue}", summaryValue)
.replace("{status}", status)
out << outputString
}%>
Output: " Notification - etc..."
Configuration
import com.atlassian.jira.component.ComponentAccessor
// Get the "Bcc.." custom field
def multiSelectAddressesCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Bcc..")
// Check if the custom field value is not empty
if (issue.getCustomFieldValue(multiSelectAddressesCF)) {
// Retrieve the email addresses from the custom field
def recipients = issue.getCustomFieldValue(multiSelectAddressesCF)?.collect {
it.emailAddress
}?.join(",")
// BCC Email List
mail.setBcc(recipients)
} else {
// Custom field is empty, log the condition
log.warn("Skipping BCC setting because the 'Bcc..' custom field is empty.")
}
// components
def notificationValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Notification Email")?.getValue(issue)?.toString()
def resolvedValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Resolve")?.getValue(issue)
def updateValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Business Notification Update Select")?.getValue(issue)?.toString()
def correctValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Business Notification Correction")?.getValue(issue)?.toString()
def summaryValue = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Notification Summary")?.getValue(issue)?.toString()
// Notification Mapping
def notificationMappings = [
"Proactive Maintenance":"Notification - {notificationValue} - {summaryValue}{status}"
]
// Status Conditions
def status = ""
if (correctValue == "Yes") {
status = " - CORRECTION"
} else if (resolvedValue != null) {
status = " - RESOLVED"
} else if (updateValue == "Yes" && resolvedValue == null) {
status = " - UPDATE"
}
// Retrieve the output string from the map
def outputString = notificationMappings.get(notificationValue)
if (outputString) {
// Replace placeholders with actual values
outputString = outputString.replace("{notificationValue}", notificationValue)
.replace("{summaryValue}", summaryValue)
.replace("{status}", status)
mail.setSubject(outputString)
}
Output: " Notification - etc..."
For your subject template and configuration, can you modify the outputString variable slightly with:-
outputString[1..outputString.length() - 1]
So that it will remove the first empty character.
Also, please update your ScriptRunner plugin to the latest release, i.e. 8.11.0 so you can use ScriptRunner's HAPI feature and simplify your code.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Hey @Ram Kumar Aravindakshan _Adaptavist_
That worked! Thank you for the help.
Also we are currently waiting until moving to DC as we expect some scripts to fail going to the latest release. When moving we'll have the appropriate time to fix as we go. I'm looking forward to HAPI!
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.