Forums

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

ScriptRunner Get Issue SLA information

David Harkins
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.
April 7, 2022

We want to get both the SLA total time and remaining time for an issue.

I'm using the following from Adaptavist to attempt to get the remaining time:

https://library.adaptavist.com/entity/copy-sla-information-to-a-custom-field

In a Debug script in TEST i have the following script:

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import org.apache.log4j.Logger

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

def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
def LogEntry = Logger.getLogger("Jira Log")
LogEntry.setLevel(Level.INFO)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def jqlSearch = "Key=LOGS-36590"

SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.results.collect {issueManager.getIssueObject(it.id)}
issues.each { issue ->
LogEntry.info("ISSUE ID": + issue.id)

// https://library.adaptavist.com/entity/copy-sla-information-to-a-custom-field
// SLA field name
final slaName = 'Open To Close'

// Gets the SLA information querying SLA service for the current issue
// https://docs.atlassian.com/jira-servicedesk/3.8.4/com/atlassian/servicedesk/api/sla/info/SlaInformationQuery.Builder.html
def query = slaInformationService.newInfoQueryBuilder()
.issue(issue.id)
.build()

//https://docs.atlassian.com/jira-servicedesk/3.8.4/com/atlassian/servicedesk/api/sla/info/SlaInformationService.html
def slaFormatter = slaInformationService.durationFormatter
def sla = SlaInformationService.getInfo(user, query).results.find { it.name == slaName }

}
} else {
LogEntry.error("Invalid JQL :" + jqlSearch)
}
LogEntry.info("Completed")

I get the following in the log Output

INFO [Jira Log]: {ISSUE ID=449689}

ERROR [common.UserScriptEndpoint]: *************************************************************************************
ERROR [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.servicedesk.api.sla.info.SlaInformationService.getInfo() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, com.atlassian.servicedesk.internal.sla.info.SlaInformationQueryImpl) values: [David.Harkins(JIRAUSER20408), com.atlassian.servicedesk.internal.sla.info.SlaInformationQueryImpl@3df9c36]
Possible solutions: notify()
at IssueSLA_Details$_run_closure2.doCall(IssueSLA_Details.groovy:41)
at IssueSLA_Details.run(IssueSLA_Details.groovy:26)

I kind of expected this to work first time, but no such luck.

Can anyone provide some pointers in the right direction?

 

1 answer

1 accepted

4 votes
Answer accepted
Salzi
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.
April 7, 2022

there is a missspelling in Line 41

def sla = SlaInformationService.getInfo(user, query).results.find { it.name == slaName }

try 

def sla = slaInformationService.getInfo(user, query).results.find { it.name == slaName }  
David Harkins
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.
April 7, 2022

@Salzi 

Thank you so much, though I do feel a little stupid now.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events