Groovy Script validator for user and a field

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 


1 answer

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,082 views 4 9
Read article

Atlassian User Groups

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!

Find my local user group

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

Groups near you