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
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. :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.