Using ScriptRunner, how do I return who approved a Jira issue?

Jeramy
Contributor
August 19, 2024

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.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.approval.ApprovalService
import com.atlassian.servicedesk.api.approval.ApprovalDecisionType
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk")

//Get LOGS issue
Issue 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

2 answers

0 votes
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.
August 21, 2024

@Jeramy 

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}")
}

0 votes
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 19, 2024

@Jeramy -

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

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.
August 21, 2024

@Joseph Chung Yin 

I work with @Jeramy 

  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?

Suggest an answer

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

Atlassian Community Events