It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

getFieldByName() in validators

I want to use the exact same code as in this ticket:    


 Kristian Walker -Adaptavist-


I want to add it in validators, I tried in both "Custom Script Validator" and "Simple scriped validator", but getFieldByName() in not recognized in the script.


How can this be solved? Thansk in advance

1 answer

1 accepted

0 votes
Answer accepted
Leo Community Leader Nov 28, 2019

Hi @Maro Hamamjyan,

I suppose the script you mentioned is for Behaviour and some methods are vary from beviours to post-function/validator/listerner

hopefully below snippet will solve your getting custom field value 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Custom Field Name")
def value = issue.getCustomFieldValue(cf) as Date




Hi @Leo 

Thank you for the code. I want to check if my custom field named "End date" is less than today+30 days, the reporter should get validation error and should not be able to create the ticket. For that I used this (Attaching the screenshot), I know I must write the error message in the error message box, but how can I connect it with the condition?


Leo Community Leader Nov 28, 2019

@Maro Hamamjyan,

you are almost there, "setError" method will work in behaviour but not in validator

Just place the message in Error field and "return false" in your script that will throw your error message in the screen

if(validation passed){

    return true // will allow the transition

} else{

    return false //will block the transition


hope it gives some idea




HI @Leo 

Thank you very much, it worked!

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you