Using ScriptRunner, how do I return who approved a Jira issue?
Asked by Jeramy:

We have an approval process, with just one approval level. I'm using ScriptRunner to try and capture who approved the issue so I can pass it onto a new issue that gets created after the approval process.

Everything that I've found online or using AI does not give me the results that I'm looking for.

Here's the script that I'm using to test this functionality. In this example, someone named Tim approved Key-123.  

```
import com.atlassian.jira.issue.Issueimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.servicedesk.api.approval.ApprovalServiceimport com.atlassian.servicedesk.api.approval.ApprovalDecisionTypeimport com.onresolve.scriptrunner.runner.customisers.WithPlugin@WithPlugin("com.atlassian.servicedesk")//Get LOGS issueIssue logissue = Issues.getByKey("Key-123")def approvals = logissue.getApprovals()//def approvalService = ComponentAccessor.getOSGiComponentInstanceOfType(ApprovalService)//def approvalUser = approvalService.getApprovals(logissue)//def approvalUser = approvals[0].getApprovers().getProperties().getClass().methods.collect { it.name }def approvalUser = approvals[0].getApprovalCondition().getMetaClass().methods.collect { it.name}//.getClass().methods.collect { it.name }return approvalUser
```


Answers:
author: David Harkins
body: [@Jeramy](/t5/user/viewprofilepage/user-id/5099791)

I've Got It  

```
def approvals = logsIssue.getApprovals()
approvals.each { approval ->
    approval.getApprovers().each{ approver ->
        if (approver.getApproverDecision()) {
            jiraLog.info("Status: " + approver.getApproverDecision().get())
            jiraLog.info("User: " + approver.approverUser.getName())
        }
    }
    jiraLog.info("Completed Date: ${approval.getDecision().get().completedDate}")
    jiraLog.info("Decision: ${approval.getDecision().get().decision}")
    jiraLog.info("Approval ID: ${approval.id}, Status: ${approval.statusId}, Approver: ${approval.id}")
}

```


author: Joseph Chung Yin
body: [@Jeramy](/t5/user/viewprofilepage/user-id/5099791) -

Can you provide more information on your ask?

1) Have you try to use Automation for Jira (This is a part of your DC version now), where you can create automation rule to obtain issue related data based on issue events. This means that you may not need to use ScriptRunner for Jira for this action.

2) On the new issue, how do you create the new issue that you want to pass in your other issue's approver user info? Via ScriptRunner? You can also use automation rule setup to create the new issue where you can pass in the approver user info to the new issue.

Please advise, so we can assist further.

Best, Joseph

comments: author: David Harkins
body: [@Joseph Chung Yin](/t5/user/viewprofilepage/user-id/396739)

I work with [@Jeramy](/t5/user/viewprofilepage/user-id/5099791)

1. Automation for Jira is not an option as our primary processes are managed via ScriptRunner.
2. We use a listener that detects when an issue in one project is approved to then create a new issue in a 2nd project.

We have all of this working, apart from extracting the ApplicationUser object of the user who approved the first issue.

We can get the Decision and date:  
approvals\[0\].getDecision().get().decision  
approvals\[0\].getDecision().get().completedDate  
Approvals has a size of 1, as one user has approved the issue, where and how do we get the user details?


Tags: jira-service-desk-data-center

jira-service-management

jira-service-management-data-center

jira-service-management-server

server