I'm looking at adding Approvals to my workflow. I DO NOT want the ticket reporter/creator to be the approver/Reviewer. What is the most efficient way to accomplish this?
Now the person that has entered the request (reporter), should not be the approver/Reviewer. In case they are the same, the request should not go to the approver.
The approvers are listed and chosen from a custom field (single select).
What is the groovy code/JSU/JMEW to create this validator?
Hi @Thomas Schlegel , @JamieA
How to achieve this via Script Runner Custom Validator? Could you please help me on this.
Hi @Andrews
Apologies for delay in response.
Script Runner's validator is able to handle this.
You will need to do some configuration as well.
1) Add a custom field - for example a Single User Picker. The Print Screen Below I've added the Approver field which is a Single User Picker.
2) Configure the workflow and set the approver. In the print screen below, I'm choosing a In Progress and setting the Add Approval option.
3) Next select the configuration and set the field in which you want to display the approvers.
4) Once that is done, you will need to add a new validator into the transition. To add the validator, select Script Validator [ScriptRunner] -> Simple Scripted Validator
Below is a sample code that I have used
issue.reporter.username != cfValues["Approver"].username
The field that I am setting this for is the Approver field. Below is a print screen of my configuration.
So now, when I create a new issue for this project, if the Reporter and Approver are the same, the ticket will return a message and cannot be created.
Below is a print screen of the validation
Hope this helps :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, Ram.
But I achieved this through JMWE plugin validator.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_ Will this solution work on JSD portal??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Yogesh,
To answer your question, yes it should work the same in the JSD portal.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nope its not working
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Yogesh Mude
I have tested this on the JSD portal and it does work. The only difference is the display of the error message.
You will, however, need to make some changes to your configuration.
Go to the project.
1) Select the project's cog.
2) Next, select Request types.
3) Either add a new Request type or modify your existing Request type as shown below.
Make sure that the field you want to use is included in the Request Type as shown below:-
Next, you will need to modify the workflow slightly.
As shown in the print screen below, you will need to add a validator for the create transition.
You can use the same example I provided in my earlier comment i.e.
issue.reporter.username != cfValues["Approver"].username
Once this is done you can start to test it.
1) First login as shown below and select the project you want to use. In the example below I am logging in as an Admin user.
2) Next, create a sample ticket and select the approver as the same user you log in as. In the print screen below, I have logged in as the Admin, and I have also selected the Admin as the approver. When I try to create the ticket, the Error message is displayed.
3) Next, I try to create the ticket once again, but this time instead of selecting the Admin (logged in user) as the approver I have selected another user
4) The ticket is created successfully
Hope this helps to answer your question :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_
I have tried your solution and steps above but it still does not work for me.
We have an "Approvers" field which is a user picker (multiple users). And I tried to insert this script as mentioned in your steps:
issue.reporter.username != cfValues["Approvers"].username
However during testing, it still does not work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jeno, I think in your case because you are using a multi-picker, your result will not be a single object, but a collection. Hence the collection won't understand the username field. You'd need to iterate over the collection to make sure none of them are the reporter, or do something like username not in approvers. That's not actual syntax, mind you, just the concept.
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.