Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can I use ScriptRunner to find out who approved an issue

Kimi Nakashima April 6, 2021

We have a change request and I'm having some difficulties trying to make it so that we don't have one person approving the same issue twice. Our change request workflow has 2 statuses that require an approval to transition: "Waiting Approval Level 1" and "Waiting Approval Level 2". Each of the approvals has it's own group of approvers: Approvers Level 1 and Approvers Level 2. This wouldn't be a problem if we didn't have an overlap of 3 agents between the 2 groups.

What I would like to do is after the 1st approval has been done, set the user picker for the 2nd approval to be everyone in "Approvers Level 2" minus the approver from the 1st approval.

Jira has a function that will tell me who can approve the request but nothing that will tell me who approved the request. I've looked at a test issue in the API and I've seen the information I need in it, but I'm not sure how to get it in a useable form. I'm hoping that this is something ScriptRunner can do, but before I head down that rabbit hole, I'd like to know if it's even possible to use ScriptRunner to find out who approved an issue.

1 answer

0 votes
John Chin
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.
April 7, 2021

Hi @Kimi Nakashima ,

You can add this script in the 1st approval and set the desired user on the Approvers field to whom you want the user to approve the second level.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

List<ApplicationUser> approversList = new ArrayList<>()

//find the Approvers custom field
def approversCF = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find {it.name == "Approvers"}

//get the second level approver user
ApplicationUser botUser = ComponentAccessor.getUserManager().getUserByName("admin")

//add the user to the approver list
approversList.add(botUser)

//set the approver list to the Approvers custom field
issue.setCustomFieldValue(approversCF, approversList)

For more clear to where set the script:

Screenshot 2021-04-07 at 6.12.52 PM.png

It will change the approver user (to your desired users) after the 1st approval. 

I hope this helps.

Do let us know if you have any question.

John Chin

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events