Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner: How to list approvers?

I'm trying to write script to notify approvers via slack ot issue transition.
I choose script listener (not post-finction) due to large number of possible transitions.
So how to do following:

  1. Detect if issue require approval
  2. Get list of approvers (later with their descisions)

I've done that before on cloud version via REST API, there is no problem with that, but in server version I've got original issue (not after transition) so there is no approval yet in moment of transition. I've try to access approval custom field, but there is no approvers info in it.  I've try to search examples how to work with approvals in scriptrunner, but no dice. I've try following code to test jira java api, but it's not working...

@WithPlugin ("com.atlassian.servicedesk")
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.approval
def issue = ComponentAccessor.getIssueManager().getIssueObject("DVPT-1")
ApprovalQuery query = approvalService.newQueryBuilder().issue(issue).build()

it shows error about "ApprovalQuery" class. What I need to import to have it?

How to work with approvals?

6 answers

Hi Kirill,

The Approvals and the Approvers are actually custom fields, therefore you can retrieve their values in the usual way 

import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.getIssueManager().getIssueObject("SD-2")

def approversCF = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find { == "Approvers"}
def approvers = issue.getCustomFieldValue(approversCF)

log.debug approvers //a list of ApplicationUsers

def approvalsCF = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find { == "Approvals"}
def approvals = issue.getCustomFieldValue(approvalsCF)

log.debug approvals // a list of Approval see

Jira Server 7.11?
Actually, you are waaay wrong /-)

You script returns:

2018-07-17 16:38:48,068 INFO [runner.ScriptRunnerImpl]:
2018-07-17 16:38:48,072 INFO [runner.ScriptRunnerImpl]: com.atlassian.servicedesk.plugins.approvals.internal.customfield.ApprovalsCFValue@475f642

 I found the way to get those values, but another bug (no values on transition) prevents me from implement listener script:

import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.getIssueManager().getIssueObject('DVPT-1')
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()"User: $")

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.servicedesk.api.approval.ApprovalService


def approvalService = ComponentAccessor.getOSGiComponentInstanceOfType(ApprovalService)
def approvalQuery = approvalService.newQueryBuilder().issue(
def approvalEither = approvalService.getApprovals(currentUser, approvalQuery)
def approvals = approvalEither.isRight() ? approvalEither.right : []
def pendingApproval = approvals.find{!it.getDecisionDetails().getOrNull()?.getDecision()}
def approversList = []
if (pendingApproval) {
def approversEither = approvalService.getApprovers(currentUser, pendingApproval)
def approvers = approversEither.isRight() ? approversEither.right : []
= approvers.findAll{!it.getApproverDecision().getOrNull()}.collect{it.getApproverUser().name}"Pending approval of: $approversList")


The ApprovalCFValue is a collection of approvals

public ApprovalsCFValue(Collection<Approval> approvals) {
this.approvals = approvals;

Do not try to overcomplicate things, those are custom fields treat them as custom fields. 

Colud you drop me a working code for listing pending approvers please? 

Code should return just a list of login...

Thank you!

@kilinich do you have any working code? Share it please, I can't make my script (that based on this topic) works.

Nope, Adaptavista confirm that problem but there is no solution yet, so I add notification in post-function instead of listener

Not working in Jira 8 anymore. Need code update!

That's what I came up with:

import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.approval.ApprovalService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
logs = Logger.getLogger("com.acme.customListener")

def issue = ComponentAccessor.getIssueManager().getIssueObject("DVPS-7011") // console testing

def robotUser = ComponentAccessor.getUserManager().getUserByKey("robot-manager")
def approvalService = ComponentAccessor.getOSGiComponentInstanceOfType(ApprovalService)
def approvalQuery = approvalService.newQueryBuilder().issue(
def approvalOpt = approvalService.getApprovals(robotUser, approvalQuery).findFirst()
if (approvalOpt.isPresent() && !approvalOpt.get().getDecision().isPresent()) {
def approvalsNeeded = approvalService.getApprovers(robotUser, approvalOpt.get()).findAll{!it.getApproverDecision().isPresent()}.collect{it.getApproverUser().name}"Approvals needed: $approvalsNeeded")
// Remind to approve
} else {"No pending approvals found for issue [$issue.key]")


@Vadim Lutsevich I've got code for Jira 8 now.

Thanks! But I realized this feature via JQL :)

To list approvers? 

A bit simpler via customField:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.approval.ApprovalService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
def issue = ComponentAccessor.getIssueManager().getIssueObject("DVPS-7010") // For console testing
def robotUser = ComponentAccessor.getUserManager().getUserByKey("robot-manager")
def approvalService = ComponentAccessor.getOSGiComponentInstanceOfType(ApprovalService)
def approval = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Approvals').first()).getApprovals()
if (approval && !approval.first().getDecision().isPresent()) {
def approvalsNeeded = approvalService.getApprovers(robotUser, approval.first()).findAll{!it.getApproverDecision().isPresent()}.collect{it.getApproverUser().name}"Approvals needed: $approvalsNeeded")
// Remind to approve
} else {
log.warn("No pending approvals found for issue [$issue.key]")

Nicely done! The code was very helpful!

We had a case where we needed to implement approving issues via e-mail. We used a script for that. At first, we implemented only issue transitions based on the content of the mail. That wasn't good because the approvals did not get recorded and approvers didn't see their approved issues. 

This code was a good basis to get what we needed and to trigger transitions and to get approvals to register.

Example snippet, if anyone should need it:

if(unansweredApproval!=null && approvalService.canAnswerApproval(approver,unansweredApproval)){
} else if(com.getBody().contains("Decline")){

The only thing that didn't work for us was 


It returned the firs approval. Which is ok if you only have one level of approval. But it, in the end, was simple to find the one approval that doesn't have a decision.

Anyways, thanks for the post. I wanted you and other participants to know that somebody found it useful. :)




Hi All,


How to get the user who approved the ticket and then set him as assignee  to that ticket. second part is easy but im struggling with first one.

Suggest an answer

Log in or Sign up to answer
Community showcase

All you wanted to know about customer support KPIs

When working in customer support, it’s crucial to calculate, analyze and monitor specific numbers, called KPIs (Key Performance Indicators). They go hand-in-hand with customer satisfaction, problem d...

133 views 1 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you