Copy SLA information to a Custom Field

Overview

This script helps you to copy a SLA field to another custom field.

Example

As a project manager, I want to export SLA field to an Excel file. The default SLA field does not export correctly, so a custom field with a copy of the SLA information can be created for later export.

Good to Know

  • Use Text Field (multi-line) as template for the custom field.

Requirements

    
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 = '' // 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?.isPresent()) { // If there is an ongoing SLA. it takes the current ongoing SLA remaining time and format it as duration of "X hours Y minutes" 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" slaFormatter.format(user, sla.completedCycles.last().remainingTime) }
Discovered an issue? Report it here

Suggested for you