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

Looking for $ variable in a Service Desk approval URL for Groovy

Steve Letch August 27, 2019

So I'm testing a looped transition that I can automate and send a custom email via Scriptrunner to remind approvers about a pending approval. I'm trying to configure a button using the same url structure as the native approve/decline buttons

 

There appears to be a variable in the URL which changes every time an issue enters the approval status that I need to accommodate for. the variable occurs after the issue key in the url. For example

 

https://help.octopusgroup.com/servicedesk/customer/user/approval-action/OSD-53800/1235/approve/analytics?sda_source=notification-email

 

The 1235 will increment to 1236 after the loop to trigger the custom email so I need to call a variable otherwise you will just receive an error 'the approval has been decided' in the portal.

 

My current url is this

 

https://help.octopusgroup.com/servicedesk/customer/user/approval-action/$issue.key/1235/approve/analytics?sda_source=notification-email

 

Does anyone know what the variable is that gets incremented when a ticket enters/re enters the approval status.

1 comment

Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 16, 2019

HI @Steve Letch did you find something about this? Im looking for the exact same thing but I dont know if this number is stored in the ticket in any form.

Hauke Bruno Wollentin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 16, 2020

I looked for the same kind of ID.

After inspecting an issue by its JSON object via https://jira.example.com/rest/api/latest/issue/FOO-1234 I saw that the whole approval is mapped to or saved in an custom field.

The ID in the URL is the ID of the approval, e.g.:

Screenshot_20200116_160144.png

The approval link for the issue above would be https://jira.example.com/servicedesk/customer/user/approval-action/FOO-1234/16/approve

Hope that helps someone :)

Anneta Svircenkova February 13, 2020

Hi @Steve Letch have you managed to get this Approval ID using groovy script? I am also looking for the same solution. Thank you! :) 

Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
February 13, 2020

Hi @Steve Letch , @Anneta Svircenkova , @Hauke Bruno Wollentin 

I found a solution for this with the ServiceDesk API with ScriptRunner. Here is the code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserUtils
import com.atlassian.servicedesk.api.approval.Approval
import com.atlassian.servicedesk.api.approval.ApprovalQuery
import com.atlassian.servicedesk.api.approval.ApprovalService
import com.atlassian.servicedesk.api.util.paging.PagedResponse
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk")

ApprovalService approvalService = ComponentAccessor.getOSGiComponentInstanceOfType(ApprovalService)

ApprovalQuery query = approvalService.newQueryBuilder()
.issue(123) //Change with de issue ID
.build()
ApplicationUser admin = UserUtils.getUser("Administrator") // Change with your admin user
PagedResponse<Approval> approvals = approvalService.getApprovals(admin, query)
approvals.each {
log.warn it.getId()
}
Like # people like this
Steve Letch February 13, 2020

Noice thanks

Martin Fransson
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 1, 2021

Hi Alejandro,

Thanks for this example, it is just what I am looking for as well. I have just one follow up question: How do I set the ID to a variable within the script instead of writing it to the log?

Javier Pérez April 14, 2021

When this is executed in a transition or a script listener, looks like approvals variable is not being populated yet and I get null, works in the preview though

Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
April 17, 2021

Hi @Javier Pérez as far as I remember, you have to listen to the "ApprovalRequestedEvent" to catch the Issue in the moment that it has the approval Id.

If you try to catch the id when you do the transition (in the event of the transition) the id is not setted yet, and it will return null.

Javier Pérez April 19, 2021

oh... that's the trick!

 

Gracias Alejandro.

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events