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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.