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