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

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,316 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot