I am trying to add one Validator into my workflow with one simple condition .
If the user = "abcd" and field = yes then create else give an error "Please fill all the Value"
and if the user !="abcd" then dont check the field just create it
how can i achieve this in Groovy .
Your Help is really appreciated
Using ScriptRunner, you can go to the workflow of the project that you would like this validator to be present. Then, when editing the workflow, click on the diagram view and select the "Create" transition. There will be a pop-up to the right, click "Validators" in the pop-up and then select "Add Validator." Select "Script Validator" and choose a "Simple Scripted Validator."
In the condition, to do what you're looking for, you'll need to put something link this:
import com.atlassian.jira.component.ComponentAccessor def userManager=ComponentAccessor.getUserManager() currentUser.equals(userManager.getUserByName("Some User)) && cfValues['Some Custom Field'] == 'Some Value'
Something like this would validate for any custom field that you specify. If you're just trying to see if the field is set, change the second part of the condition to:
cfValues['Some Custom Field'] != null
I tried the below but it is not allowing to create ticket
Just test the first condition.
import com.atlassian.jira.component.ComponentAccessor import org.apache.log4j.Category def userManager=ComponentAccessor.getUserManager() currentUser.equals(userManager.getUserByName("wtuscan")) && cfValues['Some Custom Field'] == 'Yes'
Saved the validator . when user wtuscan is trying to create a ticket with "Some Custom Field" == Yes it is giving error , it should allow it .but its not . when "Some Custom Field" == No then it should give error .
So, that script will only allow the wtuscan user to pass the validator. I think you'd want something more like
import com.atlassian.jira.component.ComponentAccessor def userManager=ComponentAccessor.getUserManager() !currentUser.equals(userManager.getUserByName("wtuscan")) || cfValues['Some Custom Field'] == 'Yes'
That should return true any time that the user isn't wtuscan OR the user is wtuscan, but they filled in the custom field with the value of "Yes". Does that make sense?
@Jonny Carter [Adaptavist]
I tried the above code . but its not working.
What i am trying to do is
if the custom field is not selected then it doesnt matter who is the user
but if the user is wtuscan "and" the custom field is selected to YES then it should allow to create ticket
Badges are a great way to show off community activity, whether you’re a newbie or a Champion.Learn more
...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs