Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Find first non null date from custom fields

David Sumlin
Contributor
September 19, 2019

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
Tuncay Senturk _Snapbytes_
Community Champion
September 19, 2019

Hi @David Sumlin 

I hope this works for your case

def dates = [date2,date3,date4,date1]
return dates.findResult { (it != null) ? it:null }
David Sumlin
Contributor
September 19, 2019

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

Suggest an answer

Log in or Sign up to answer