I want my SLA to show how many SLAs are met/exceed until issue is resolved

Context: A user wants to track the time between an external comment and a public comment made by one of their agents.

Use Case: As a Project Manager, I want to track the time between an external comment and a public comment made by one of our agents. But I’d also appreciate a perspective on the % of responses made within two days.

Solution: Using the Time to SLA Issue Actions menu to Reset the SLA!

To examine this use case, let’s assume the user’s workflow is as follows:

Solution

1. Configure an SLA (named Response SLA, in this example) with the following parameters:

SLA Start: Waiting for Support

SLA End: Waiting for Customer

SLA Goal: 2d

Calendar: Choose any calendar that fits your use case

Calculation Method: Last Cycle

Note: Please limit this SLA to the workflow that is shown above, like this:

2. Set the SLA Reset condition in the Waiting for Support transition.

This allows the SLA to restart when an issue transitions to Waiting for Support status.

You can set up Automation Rules for this workflow to automatically transition to the Waiting for Support status when a customer enters a comment. Similarly, you can set up an automation rule for this project to allow issues to transition to Waiting for Customer status when a public comment is made by agents.

3. Create three custom fields (single-line text field) named "Exceed Count", "Met Count" and "Total Count". Add these fields to the projects view issue screen with a default value of 0. Click on the cog icon > Edit and take a look at the URL of the page and note the custom field id present in the URL. 

4. Place the following script in the first place in the "Waiting for Customer" transition.

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder def customFieldManager = ComponentAccessor.getCustomFieldManager() def issueManager = ComponentAccessor.getIssueManager() //find your met count, exceed count and total count id's and put it here instead of 12000,12001, and 12002 def metField= customFieldManager.getCustomFieldObject(12001) def exceedField= customFieldManager.getCustomFieldObject(12000) def totalField= customFieldManager.getCustomFieldObject(12002) String metFieldValue_string= issue.getCustomFieldValue(metField) String exceedFieldValue_string= issue.getCustomFieldValue(exceedField) String totalFieldValue_string= issue.getCustomFieldValue(totalField) Integer metFieldValue= metFieldValue_string.toInteger() Integer exceedFieldValue= exceedFieldValue_string.toInteger() Integer totalFieldValue= totalFieldValue_string.toInteger() def changeHolder= new DefaultIssueChangeHolder() // find your SLA Overview field's ID and put it here instead of 10303 def overviewField = customFieldManager.getCustomFieldObject(10303) def overviewFieldValue = issue.getCustomFieldValue(overviewField) def slaStatus="" // SLA Overview field returns a list and we'll get the SLA indicator information if (overviewFieldValue) { overviewFieldValue.each { slaStatus = it.status } } if (slaStatus.toString().equals("EXCEED")){ exceedFieldValue=exceedFieldValue+1 exceedField.updateValue(null,issue,new ModifiedValue(issue.getCustomFieldValue(exceedField),Integer.toString(exceedFieldValue)),changeHolder) totalFieldValue=exceedFieldValue+metFieldValue } else if (slaStatus.toString().equals("STILL") || slaStatus.toString().equals("SUCCESS")){ metFieldValue=metFieldValue+1 metField.updateValue(null,issue,new ModifiedValue(issue.getCustomFieldValue(metField),Integer.toString(metFieldValue)),changeHolder) totalFieldValue=exceedFieldValue+metFieldValue } totalField.updateValue(null,issue,new ModifiedValue(issue.getCustomFieldValue(totalField),Integer.toString(totalFieldValue)),changeHolder)

5. Save the script, and you're done!

This guide assumes that only the Response SLA is active in this workflow. If there are more SLAs, you need to modify the above script accordingly.