Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Auto Approve an issue using ScriptRunner

Nick Hassell
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.
January 31, 2020

I would like to mimic the Service Desk Automation function of Auto Approve in a ScriptRunner Script Listener.

I have tried the following:

def result = post("/rest/servicedeskapi/request/${issueKey}/approval/<userid>")
.header('Content-Type', 'application/json')
.body([
fields:[
decision: "approve"
]
])
.asString()

But this returns a 401 error.  The user id I am using is set as an Approver.

The documentation I am following is: here 

It says that "The approval is assumed to be owned by the user making the call." but I don't understand this - how does an approval have an owner?

2 answers

1 accepted

2 votes
Answer accepted
Nick Hassell
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.
January 31, 2020

After much trial and error, I think I now understand.

Approvals are objects with a set of properties - including whether or not the Approval is required, who the Approvers are etc.  You can have multiple Approvals per issue.

Where I had <user id> I should have supplied the ID of the Approval to be approved.

So to do an Auto Approve, you have to do the following:

- set the Approvers field with the ScriptRunner user id (assuming you are running the script as this id)

- get the list of Approvals

- get the id of the Approval that is waiting for approval (and check that it is can be answered)

- provide the Approval, supplying the ID of the Approval

Angga Putra April 25, 2020

Hello @Nick Hassell ,

I having same problem in here, trying to auto approve issue with automation or scriptrunner when comment added like when approver reply email "Approve" then automation process it,

 

im oke if the issue just have 1 approvers, it can be done use automation. But i found automation for jira cannot handle this when the issue have more than 1 approvers,

for example i have 1 issue with 4 approvers, email send to the all approvers, but when 1 approvers reply email "approve", approval status in the issue become "Approved" and skip all the rest approvers.

 

Do you have any code that run auto approve in scriptrunner?

 

Thankyou,

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 29, 2023

Did anyone get this working withing a ScriptRunner Post Function?

Malene Vikkelsø
Contributor
October 28, 2024

Hi @Nick Hassell 

In your follow up comment you mentions the sets you must take with

"get the id of the Approval that is waiting for approval (and check that it is can be answered)"

Could you add a few words on how you get the approval id?

Cheers.

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.
October 29, 2024

If using ScriptRunner, it may be worth looking at:
HAPI - Approving an Issue 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events