I would like to know if it's possible, using ScriptRunner, to restrict who approves tickets created within a software project.
I have a custom field Approvers (Single Select).
The people who can be added as approvers are defined in the users and groups of the project,
I used validation on the workflow to make sure the Reporter and Approver are not the same person.
I now have to make sure that the approvers selected is the only person who can press the approval button and not anyone in this group.
I have behaviour scripting for the Reporter and Approver to not be the same
How do I change it to validate that the selected approver is the one that press the approval button and not anyone in the group?
// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the changed field
def approversField = getFieldByName("Approvers (Single)")
def reporterField = getFieldById("reporter")
//def userInPickerCF = it.getCustomFieldValue(approverFieldValue)
if(!(approversField.getValue()?.toString().equals("")))
{
if(approversField.value.toString() == reporterField.value.toString()
/* || currentUser.key == approversField.value.toString() */|| reporterField.value.toString() == approversField.value.toString())
{
approversField.setError("Please select a different Approver (Approver must not be the same as Reporter)")
}
else
{
approversField.clearError()
}
}
You can use a Condition in your Approve transition to ensure that only the user in the Approvers custom field can see the Approve button.
I have this condition. It still allows everyone in the role of the approvers to see the ticket.
I want only the selected approver to see the approval button and not everyone in the group.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I opted to use the workflow functions to assign the ticket to the selected approver and then to have a condition that only assignee can approve the request as well as be in the group/role.
Then I added a post function to clear the assignee field.
This will also help with notification of the assigned ticket.
No need for scripting.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's great to have the ability to use scripting to meet requirements. But it still adds some maintenance overhead. So if you can meet your requirement without scripting, that's always best.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.