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

Find first non null date from custom fields

I'm creating a post function in a workflow.  I have 4 different date fields on the issue.  (example: Date 1, Date 2, Date 3, Date 4)

I want to find the first non null field and return that value in my Groovy script. I have business priority logic so that I want to examine Date 2 1st, Date 3 2nd, and Date 4 3rd, and Date 1 last.

Basically, if my issue has these 4 values

Date 1: 1/1/2019
Date 2: null
Date 3: 3/3/2019
Date 4: 4/4/2019

I want my groovy code to return 3/3/2019 based on my priority logic.

I know that in SQL they have a COALESCE function, where I could do something like COALESCE(Date 2, Date 3, Date 4, Date 1)

I want to compare the returned date and then compare it to today and then trigger a subsequent action if it meets my criteria.

I'm a newbie Groovy scripter, so I'm kinda stuck

1 answer

1 accepted

0 votes
Answer accepted

Hi @David_Sumlin 

I hope this works for your case

def dates = [date2,date3,date4,date1]
return dates.findResult { (it != null) ? it:null }

Thanks!  That works. Now I just need to read up on how it works. :-)

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