Send custom email with issue details including Sub-task details

Conor McGmail October 21, 2015

Hi,

Can someone assist me in coding a custom email tempate using ScriptRunner to send an email notification that will include subtask details - subtask status, subtask custom field etc.

Previously i've been able to send custom emails using ScriptRunner but i'm really struggling to include the subtask info I need.

Your help would be greatly apprciated.

Many thanks

Conor

 

1 answer

1 accepted

1 vote
Answer accepted
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 22, 2015

Hi Conor,

I think this example should be good to begin with:

<%
def issueTypeName = issue.issueType?.name
def issuePriority = issue.priority?.name
def subTaskList = issue.getSubTaskObjects()
def firstSubTask = subTaskList ? subTaskList[0] : null 
def subTaskId = firstSubTask?.getId()
def subtaskPriority = firstSubTask?.priority?.name
def subTaskType = firstSubTask?.issueType?.name
def subTaskCustomField = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10100")
def customFieldValue = firstSubTask?.getCustomFieldValue(subTaskCustomField)
%>
Issue Name: $issue <br>
Issue typeName: $issueTypeName <br>
Issue priority: $issuePriority
Subtask Name: $firstSubTask <br>
SubtaskId: $subTaskId <br>
Subtask Priority: $subtaskPriority <br>
Subtask Issue type: $subTaskType <br>
Subtask url: <a href="$baseUrl/browse/<% out << firstSubTask?.key %>">$firstSubTask</a> <br>
$subTaskCustomField (customField): $customFieldValue
Conor McGmail October 22, 2015

Hi Thanos, Thank you for that. I've added it to my script and it works well. How would i loop through all sub-tasks for an issue and write out to an email? I presume i need to loop through issue.getSubTaskObjects() and grab the fields i need and then write that out to the email body. I'm not very familiar with groovy, and I wonder could you show me how this could be achieved? many thanks, Conor

Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 22, 2015

Hey Conor You can get all the subtasks with a for loop and concat them in a variable. //Code begin <% def issueTypeName = issue.issueType?.name def issuePriority = issue.priority?.name def subTaskList = issue.getSubTaskObjects() def subTasksText = "" def counter = 0 if (subTaskList) for (subTask in subTaskList) { def subTaskId = subTask.getId() def subtaskPriority = subTask.priority?.name def subTaskType = subTask.issueType.name def subTaskCustomField = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10100") def customFieldValue = subTask.getCustomFieldValue(subTaskCustomField) subTasksText = subTasksText + "<b>Subtask $counter </b><br> Subtask Name: $subTask <br> SubtaskId: $subTaskId <br>" + "Subtask Priority: $subtaskPriority <br> Subtask Issue type: $subTaskType <br>" counter ++ } else subTasksText = "No subtasks" %> Issue Name: $issue <br> Issue typeName: $issueTypeName <br> Issue priority: $issuePriority <br><br> $subTasksText //end of code

Conor McGmail October 23, 2015

Brilliant! Thank you :)

Suggest an answer

Log in or Sign up to answer