Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Problem

Info

Some users want to access SLA Data with scripts for further operations. We don't support it officially, but provide solutions as is.

Solution


Expand
titleGet field calculations
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.coresoftlabs.sla_powerbox.field.slametric.SlaCustomFieldModel
import com.coresoftlabs.sla_powerbox.calculate.service.SlaCustomFieldCalculateService

@WithPlugin("com.coresoftlabs.sla_powerbox.sla_powerbox")

@PluginModule
SlaCustomFieldCalculateService slaCustomFieldCalculateService

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def slaCustomField = customFieldManager.getCustomFieldObject("customfield_xxxxx")

SlaCustomFieldModel slaCustomFieldModel = slaCustomFieldCalculateService.getSlaModelUsingDefaultStrategy(issue, slaCustomField)
Long requiredSla = slaCustomFieldModel.getRequiredSla()
Long spentSeconds = slaCustomFieldModel.getSpentSeconds()
if (requiredSla == null || spentSeconds == null) {
return null;
}
Long result = Math.round((spentSeconds.doubleValue() / requiredSla.doubleValue()) * 100)
return result.intValue() 

...