Example scripts
To homepage
Jira Service Desk

Copy SLA information to a Custom Field
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira Service Desk (3.10 - 3.16)

ScriptRunner For Jira (5.6.14)

Jira Service Desk (4.0 - 4.6)

ScriptRunner For Jira (5.6.14)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.sla.info.SlaInformation
import com.atlassian.servicedesk.api.sla.info.SlaInformationService
import com.atlassian.servicedesk.api.util.paging.PagedResponse
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.atlassian.servicedesk")
@PluginModule SlaInformationService slaInformationService
// SLA field name
final slaName = '<SLA name>'
// Gets the SLA information querying SLA service for the current issue
def query = slaInformationService.newInfoQueryBuilder()
.issue(issue.id)
.build()
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def slaFormatter = slaInformationService.durationFormatter
def slaPagedResponse = slaInformationService.getInfo(user, query).right().get() as PagedResponse
def sla = slaPagedResponse.results.find { (it as SlaInformation).name == slaName } as SlaInformation
if (sla?.ongoingCycle?.present) {
// If there is an ongoing SLA. it takes the current ongoing SLA remaining time and format it as duration of "X hours Y minutes"
log.error("SLA remaining time: ${sla.ongoingCycle.get().remainingTime}")
slaFormatter.format(user, sla.ongoingCycle.get().remainingTime)
} else {
// If there is no ongoing SLA, it takes last completed cycle remaining type and format it as duration of "X hours Y minutes"
log.error("SLA remaining time: ${sla?.completedCycles?.last()?.remainingTime}")
slaFormatter.format(user, sla?.completedCycles?.last()?.remainingTime)
}
Having an issue with this script?
Report it hereLanguage |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.sla.info.SlaInformationService
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.atlassian.servicedesk")
@PluginModule SlaInformationService slaInformationService
// SLA field name
final slaName = '<SLA name>'
// Gets the SLA information querying SLA service for the current issue
def query = slaInformationService.newInfoQueryBuilder()
.issue(issue.id)
.build()
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def slaFormatter = slaInformationService.durationFormatter
def sla = slaInformationService.getInfo(user, query).results.find { it.name == slaName }
if (sla?.ongoingCycle?.present) {
// If there is an ongoing SLA. it takes the current ongoing SLA remaining time and format it as duration of "X hours Y minutes"
log.error("SLA remaining time: ${sla.ongoingCycle.get().remainingTime}")
slaFormatter.format(user, sla.ongoingCycle.get().remainingTime)
} else {
// If there is no ongoing SLA, it takes last completed cycle remaining type and format it as duration of "X hours Y minutes"
log.error("SLA remaining time: ${sla?.completedCycles?.last()?.remainingTime}")
slaFormatter.format(user, sla?.completedCycles?.last()?.remainingTime)
}
Having an issue with this script?
Report it here