Forums

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

Get AuditService from Jira API in ScriptRunner

htietgens November 15, 2021

Hi,

I try to read the Jira Audit log on Jira Server 8.13+ with ScriptRunner. But I don't know how to get the needed component AuditService.

If I run

import com.atlassian.audit.api.AuditSearchService
import com.atlassian.jira.component.ComponentAccessor

def auditSearchService = ComponentAccessor.getComponent(AuditSearchService)
if (!auditSearchService) {
log.error "No AuditSearchService found."
}

in the console, I always get the error No AuditSearchService found.

What did I miss here?

Thanks,
Henning

1 answer

1 accepted

2 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 15, 2021

Hi @htietgens , you can use

import com.atlassian.audit.api.AuditSearchService
import com.atlassian.jira.component.ComponentAccessor

def auditSearchService = ComponentAccessor.getOSGiComponentInstanceOfType(AuditSearchService)
if (!auditSearchService) {
log.error "No AuditSearchService found."
}
htietgens November 15, 2021

Thanks, that works. Is there some kind of rule or similar on how to determine if I should use getComponent() or getOSGiComponentInstanceOfType()?

Best,
Henning

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 15, 2021

Hi @htietgens in p2 projects you can have public services (marked with @ExportAsService annotation) and these types of services can be loaded only using posted method. It is safer to use this method in all cases...briefly :)

Like htietgens likes this
htietgens November 15, 2021

Ok, thanks for the information!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13
TAGS
AUG Leaders

Atlassian Community Events