Send custom email with issue details including Sub-task details

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

Accepted Answer
1 vote

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

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

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

Brilliant! Thank you :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,668 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you