Approval in Jira Service Desk

Tushar January 28, 2018

Hi,

I need property for a workflow status in JSD, where if the reporter and approver is same then the approval button should not appear or should be disabled.

1 answer

0 votes
Ivan Tovbin
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 29, 2018

Hello,

We've had a similar problem and here's how I managed to solve it.

Basically, what you do is if the reporter and approver is the same person then you simply make your issue skip the approval status. And since you have JMWE (from what I understand) it's super easy.

Let's say your workflow looks like this:

status 1 --> approval status --> status 2

1) Create two transitions: A) From status 1 to status 2 and B) From status 2 to approval status.

2) Create a post function for transition A that would trigger transition B. Add a groovy expression to execute it conditionally so that it triggers ONLY if reporter DOES NOT equal approver. Here's the code (assuming your "Approver" field ID is 11111):

import com.atlassian.jira.component.ComponentAccessor

def approverField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11111.toLong())

if (issue.getReporter() != issue.getCustomFieldValue(approverField)){
return true
}
return false

 in case your "approver" field is a multiple user picker type field then change the 'If' statement to:

if (issue.getCustomFieldValue(approverField).contains(issue.getReporter()) == false){
return true
}
return false

 3) Make sure you place this post function at the very bottom of your post functions list for this transition

Done!

What's gonna happen is that your issue will always go from Status 1 straight to Status 2, but in case the reporter and approver is NOT the same, your issue will be automatically transitioned to Approval status.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 29, 2018

Thanks Ivan for sharing your solution with the Community.

A couple of comments:

- wouldn't it be more natural to always go through the Approval status, and automatically move on to status 2 when the reporter is the approver. Kind of an automatic self-validation?

- if we stick to your approach, then I guess the workflow diagram is confusing, because status is really between status 1 and approval status since you're always first going to status 2

- also, you should then hide transition B from users (the transition that goes from status 2 back to approval)

- finally, the conditional execution scripts can be written much more concisely:

issue.reporter !=  issue.get("Approver")

and

issue.get("Approvers").contains(issue.reporter)

respectively.

Cheers,

David

Ivan Tovbin
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 29, 2018

Great points, David, cheers for the feedback! And yeah, totally forgot about hiding the transition.

Suggest an answer

Log in or Sign up to answer