Compare year value against a date custom field

arturo_penas_petrobras_com September 27, 2019

Hi everyone,

How can I compare a text field that contains the numerical value of a year (for example "2019") to know if it is greater than a date type field (for example the date of creation of the issue that presents a format dd.mm.yyyy)?

I need to incorporate the condition into a transition.

Many thanks!

1 answer

0 votes
Abdulkarim Itani September 27, 2019

This works like a charm, dont forget to change the fields ids:

 

import com.atlassian.jira.component.ComponentAccessor


def cfm = ComponentAccessor.getCustomFieldManager()

Date date = (Date)issue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_11100")) // date field id
int dateYear = date.format("yyyy").toInteger()

String year = (String)issue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_10809")) // year field id
int fieldYear = year.toInteger()

return dateYear < fieldYear

 

This will allow the transition if the year (text field) is greater than the date (date field)

arturo_penas_petrobras_com October 9, 2019

Good morning Abdulkarim,

Thank you for the suggestion.

I need the control to be done in a transmission through a validation function. Could you tell me where I insert or apply the source code ? or if it requires a special plugin ?

Abdulkarim Itani October 10, 2019

To add any code you will need scriptrunner plugin

Suggest an answer

Log in or Sign up to answer