how to validate a custom dropdown field value against another dropdown field value in JIRA

Mamta Verma July 25, 2018

Suppose we have 2 dropdown fields:  Requested date &  Target date

the scenario is:

  1. Requested date (single select dropdown) = 1802, 1806, 1810, 1902
  2. Target date (single select dropdown) = 1802, 1806, 1810, 1902
  3. The validation is ‘Target date’ cannot be lesser than ‘Requested date’

1 answer

1 accepted

1 vote
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 25, 2018

Hello,

What are the numbers? Are these values of the custom field or option ids?

If they are values then your code would be like this:

import com.atlassian.jira.component.ComponentAccessor
def reqDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requested date")
def targetDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Target date")
int reqDateValue = Integer.parseInt(issue.getCustomFieldValue(reqDate).toString())
int targetDateValue = Integer.parseInt(issue.getCustomFieldValue(targetDate).toString())

if (targetDateValue < reqDate) {
 return false;
}

return true;
Mamta Verma July 26, 2018

Thanks a lot! It worked :)

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2018

@Mamta Verma you are welcome!

Suggest an answer

Log in or Sign up to answer