Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

need script for Jira

Rajashekara.J May 28, 2019

Hi Team,

I want to calculate Actual time spent by User in JSD for this i need script pls share to me if any body have.

 

Goal time = 1h

Actual time spent=24mintues i want to update this time on my ticket view screen.

remaining time =36min

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2019

How are you defining time spent?  How are they entering a differing value into Jira?

Rajashekara.J May 30, 2019

based on SLA if you gine thoruth SLA You can see actual time spent by user out of SLA goal time

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2019

I know an SLA measure a length of time between updates and an agent will not start as soon as it arrives and finish when it ends (e.g. an issue that takes an hour to fix, but you've been doing more urgent stuff for six hours). 

But how are you telling Jira the actual time spent?  Where is the agent recording that they spent an hour on something?

Rajashekara.J June 4, 2019

 

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

}

Rajashekara.J June 4, 2019

Error showing like this:

 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 142: expecting '}', found '' @ line 142, column 6. } ^ 1 error at com.adaptavist.sr.cloud.workflow.AbstractScript.parseScript(AbstractScript.groovy:51) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:32) at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$1.callCurrent(Unknown Source) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:27) at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events