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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Custom Script Validator Edited

I'm trying to write a custom script on validator for following requirement

When User selects ABC component it makes due date mandatory (for other component it'll be there but not mandatory), and if user enters the duedate before 3 date from today then it'll throw an error(again only for ABC component) . I have written following script but it's not working. Any suggestions? Thanks in advance!

import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import com.opensymphony.workflow.InvalidInputException
import java.util.Date.*

def formComponent = getFieldByName("Component")

def dueDate = getFieldById("customfield_12204")
def createdDate = getFieldById("customfield_14364")
def cfval = cf.getValue() as Date

// get todays date
def today = new Date()

// get the date three months in the future
def threeDaysDate =

//def today = new java.sql.Timestamp(new Date().getTime())

def componentFieldValues = formComponent.value

if (componentFieldValues*.name?.contains("ABC")){


              if(cfval.before(threeDaysDate)) {

// if the date entered is over three months throw an error
                 }   else{
//else {

1 answer

1 vote
Hana Kučerová Community Leader Nov 14, 2020


welcome to the Atlassian Community!

I will try to help you, but please, provide me more information.

Component/s field and Due Date field you are working with - are these the Jira System fields, or did you created them as a new custom fields? If so, which types do they have?

Hi @Hana Kučerová 


Component/s and Due date both are System fields. I do have Custom Due Date as well of Date Picker type. 

Hana Kučerová Community Leader Nov 16, 2020


please try something like this:

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FormField
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS
import static com.atlassian.jira.issue.IssueFieldConstants.DUE_DATE

String componentName = "ABC"

FormField componentsField = getFieldById(COMPONENTS)
FormField dueDateField = getFieldById(DUE_DATE)

Collection<ProjectComponent> components = componentsField.getValue() as Collection<ProjectComponent>
Date dueDate = dueDateField.getValue() as Date
Date limitDate = new Date() + 3

if (components*.getName()?.contains(componentName) ) {
if (dueDate.before(limitDate)) {

You would need to add it as a server-side script for both Component/s and Due Date fields, because you would want to do the validation everytime one of the fields change.

Hi @Hana Kučerová 

Thanks for this! As I need to validate every time, I can not use any custom Scripts on Validators (Workflow)?

Hana Kučerová Community Leader Nov 17, 2020


you can use them, but it won't be very nice solution - you will probably end up having validator on each transition and force users to edit the issue using transitions and screens on them (because you need to validate every time).

So, I believe, in this case is better to use behaviours.

Hi @Hana Kučerová 

Yeah, that's correct. Thanks a lot for all your help!

Hana Kučerová Community Leader Nov 20, 2020


if everything worked for you, would you please mark my answer as accepted? This action will mark the question as resolved and it can also help other users in the future to find the solution, if they have similar problem. Thank you!

Hi @Hana Kučerová 

It definitely helped me and other day I was looking for option to accept but couldn't find. Would you mind to show me, please?

Hana Kučerová Community Leader Nov 30, 2020

Hi @SPATEL and @Spatel :-),

thank you, I think you should be able to see green button "Accept answer" on this page, but only if you are logged in as a user, who has created this question. The problem could be, that you are using two different user accounts.

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