In this case different classes in the SLAValue.class have to been checked CompletedSLAData and OngoingSLAData
The result is only showed when the status are Solved, Resolved, Done or Closed (depending on the type of issue)
In my SLA clock configuration when Solved, Resolved or Done the clock is paused, and when Closed the clock is stopped.
//////this is my code but am showing errors can u help me out this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
// ------- FUNCTIONS
// Get minutes per type of issue and priority/urgency
long goalMinutesPerPriorityOrUrgency(type, value) {
def valueCopied = value
switch (type) {
case "Incident":
result = goalMinutesPerIncidentPriority(valueCopied)
break
case "Request for Change":
result = goalMinutesPerRfCPriority(valueCopied)
break
case "Task":
result = goalMinutesPerTaskUrgency(valueCopied)
break
default:
result = 0
}
result
}
// Minutes per incident by priority
long goalMinutesPerIncidentPriority(priority) {
switch (priority) {
case "Blocker":
result = 240 //4h
break
// more cases ...
default:
result = 0
}
result
}
// Minutes per RfC by priority
long goalMinutesPerRfCPriority(priority) {
switch (priority) {
case "Blocker":
result = 240 //4h
break
// more cases ...
default:
result = 0
}
result
}
// Minutes per task by urgency
long goalMinutesPerTaskUrgency(urgency) {
switch (urgency) {
case "Critical":
result = 480 //8h
break
// more cases...
default:
result = 0
}
result
}
// ------- MAIN
// Return every value in minutes
// Status of the issue is saved
def statusName = issue.getStatusObject().getSimpleStatus().getName();
if ((statusName == 'Solved') || (statusName == 'Resolved') || (statusName == 'Done') || (statusName == 'Closed'))
{
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
// Time to Resolution custom field from SLA calculations (Service desk plugin)
CustomField cf_timeToResolution = customFieldManager.getCustomFieldObject((long))(10035) //Put your Time to Resolution custom field ID
def timeToResolution = issue.getCustomFieldValue(cf_timeToResolution)
long result = 0
def issueTypeName = issue.getIssueTypeObject().getName() // Incident, Request for Change, Task
def priorityOrUrgency = ""
// I use urgency for tasks instead of Priority
if (issueTypeName == "Incident")
{
// Get Urgency field from issue of type Task
CustomField cf_urgency = customFieldManager.getCustomFieldObject(10025) // I use Urgency for task instead of Priority
priorityOrUrgency = issue.getCustomFieldValue(cf_urgency)
}
else
{
// Get Priority value from issue of type Incident or Request for Change
priorityOrUrgency = issue.getPriority().getString("name")
}
/*
CompleteSLAData is only filled when the issue has the SLA clock stopped (passed through 'Solved' or 'Resolved' to 'Closed')
OngoingSLAData is only filled when the issue has the SLA clock running or paused.
*/
if (timeToResolution != null)
{
// SLA clock stopped - get from CompleteSLAData
if (timeToResolution.getCompleteSLAData().size() > 0)
{
// Get elapsed time from Service Desk plugin libraries after have decompiled the .jar
long timeToResolutionMillis = timeToResolution.getCompleteSLAData().get(0).getElapsedTime()
// Convert time to minutes
double timeToResolutionMinutes = timeToResolutionMillis / (1000*60)
return timeToResolutionMinutes.round().toString();
}
// SLA clock paused - get from OngoingSLAData
else
{
double elapsedTime = 0;
if (timeToResolution.getOngoingSLAData() != null)
{
// Get StarTime from OngoingSLAData
double remainingTimeMin = (timeToResolution.getOngoingSLAData().getThresholdData().get().getRemainingTime().get()) / (1000*60)
long remainingTimeMinLong = remainingTimeMin.round().longValue()
if (remainingTimeMin < 0) // RemainingTime is negative
{
elapsedTime = elapsedTime.sum(goalMinutesPerPriorityOrUrgency(issueTypeName, priorityOrUrgency), remainingTimeMinLong.abs())
}
else
{
elapsedTime = goalMinutesPerPriorityOrUrgency(issueTypeName, priorityOrUrgency).doubleValue() - remainingTimeMin
}
}
return elapsedTime.round().toString()
}
}