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

Restrict approval based on selected approver in a Software project.

Natasja Eloff January 20, 2022

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()
}
}

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Peter-Dave Sheehan
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 20, 2022

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.

Natasja Eloff January 21, 2022

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.

Natasja Eloff January 21, 2022

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.

Peter-Dave Sheehan
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 21, 2022

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.

Like Natasja Eloff likes this
TAGS
AUG Leaders

Atlassian Community Events