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

Compare year value against a date custom field

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

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)

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 ?

To add any code you will need scriptrunner plugin

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

872 views 6 24
Read article

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