How to reverse editing release dates for those are not authorized using ScriptRunner

S A May 2, 2023

I want to check when a release dates is updated, and return the user who updated the version in addition to the previous and updated date.

The audit log can show these data but I want to use scriptrunner to retrieve the data so i can store it in variables and perform function and conditions.

So is there a way to retrieve the data? 

Thanks in advance

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 2, 2023

Hi @S A

If you want to retrieve data from the Audit Logs via ScriptRunner, the best approach would be via the REST Endpoint.

Below is a sample working code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient

import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate
getAuditRecords { MultivaluedMap queryParams, body, HttpServletRequest request ->
def applicationProperties = ComponentAccessor.applicationProperties

def hostUrl = applicationProperties.getString('jira.baseurl')

def username = 'admin'
def password = 'q'
def path = '/rest/api/2/auditing/record'

final def headers = ['Authorization': "Basic ${"${username}:${password}".bytes.encodeBase64()}", 'Accept': 'application/json'] as Map
def http = new RESTClient(hostUrl)

http.setHeaders(headers)
def resp = http.get(path: path) as HttpResponseDecorator

if (resp.status != 200) {
log.warn 'Commander did not respond with 200 for retrieving project list'
}

Response.ok(new JsonBuilder(resp.data).toPrettyString()).build()
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the REST Endpoint configuration:-

reset_endpoint.png

Below is the expected output:-

audit_logs_rest_output.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

S A May 2, 2023


Hello Ram,

Thank you for responding it's very helpful.

Although I would like to ask few questions, now the purpose of retrieving the data is to try to restrict the edit on Versions specifically the release dates. first thing I considered is to retrieve the data from the audit log and then perform the condition of the users allowed ...etc. 

is there another approach where I can accomplish that? 

Thanks again.

Best Regards,

SA

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2023

Hi @S A

If you aim to get the details from the versions to restrict them, you don't need to go into the Audit Log.

Instead, you could just get the information directly from the Version History or even from the issue.

There are a couple of approaches discussed earlier, in this Community Discussion as well as this Community Discussion.

You could just do the following:-

issue.fixVersions*.releaseDate

to get the release date of a version.

I hope this helps to answer your question. :-)

Thank you and Kind regards,
Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2023

Hi @S A

Has your question been answered?

If yes, could you please accept the answer?

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer