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.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great points, David, cheers for the feedback! And yeah, totally forgot about hiding the transition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.