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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

81 views 1 0
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