Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Got errors on this script applied on jira service desk

If you want to know the spent time when the SLA clock is stopped or PAUSED

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()
}

}errors.PNG

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

183 views 2 3
View question

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you