I need to create an automation that compare 4 date picker custom fields and put the value in other
Asked by Sofia Grunspan:

I need to create an automation rule that allows me compare four date picker custom fields and put the furthest one in a custom field of the same type named "Final Date".

The problem I've found is one of those fields to be compared can be empty.

Do you have any idea how can I structure this?

I have 4 data fields which I need to compare properly whenever the value of one of them changes and then select the furthest date of all and put value of it into "Final Date" field. Unfortunately if one of them has the value 'empty' the automaton doesn't know how to treat it so I have to add also a validation that checks if the field is empty.To do this, I need to create something like this (Example for fieldA):  
----------------------------------------------------  
If FieldB is empty  
Or  
IF FieldA is after(further) Field BAndIf FieldC is empty  
Or  
IF FieldA is after(further) Field CAndIf FieldD is empty  
Or  
IF FieldA is after(further) Field DThen put value from fieldA into "Final Date"


Answers:
author: Bill Sheboy
body: Hi [@Sofia Grunspan](/t5/user/viewprofilepage/user-id/5555756)

Do you only need the maximum value or do you need to know the specific field? If you only need the maximum value...

One way to do this is to combine the date values to form a list, and then find the [maximum](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#list.max) value. For example:

* action: create variable *(This will create a comma-separated values list of the dates.)*
  * name: varDateList
  * smart value:

```
{{issue.FieldA.jiraDate}},{{issue.FieldB.jiraDate}},{{issue.FieldC.jiraDate}},{{issue.FieldD.jiraDate}}
```

* action: edit issue, to set *Final Date* to this value, which splits the values, converts them back to dates, and then finds the maximum value.

```
{{varDateList.split(",").toDate.max}}
```

This will handle if zero or more of the dates are empty, but it will not handle if all of the dates are empty. What do you want to do in that case?

Kind regards,  
Bill

comments: author: Sofia Grunspan
body: Hi Bill thanks for answer, I've tried to implement what you suggested but the value is incompatible with Final Data field type.

![1.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/342269iC7C87C4980A1AA0A/image-size/large?v=v2&px=999 "1.jpg")![2.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/342270i7158428C214087C4/image-size/large?v=v2&px=999 "2.jpg")


author: Bill Sheboy
body: Does your scheduled trigger have any JQL to provide issues to the rule steps?

That error message indicates your rule does not have an issue for a source of the edit.


author: Sofia Grunspan
body: You were right, I've corrected that and it worked.

Thanks a lot!


author: Trudy Claspill
body: Hello [@Sofia Grunspan](/t5/user/viewprofilepage/user-id/5555756)

Welcome to the Atlassian community.

Can you clarify the point you are making about one of the fields being empty? Is that a permissible state? Do you want to ignore the empty fields?

What if one of the fields gets changed after the automation has run? Do you want this automation to run every time one of the fields is updated?

comments: author: Sofia Grunspan
body: I've changed the explanation to be more clear:

I have 4 data fields which I need to compare properly whenever the value of one of them changes and then select the furthest date of all and put value of it into "Final Date" field. Unfortunately if one of them has the value 'empty' the automaton doesn't know how to treat it so I have to add also a validation that checks if the field is empty.To do this, I need to create something like this (Example for fieldA):  
----------------------------------------------------  
If FieldB is empty  
Or  
IF FieldA is after(further) Field BAndIf FieldC is empty  
Or  
IF FieldA is after(further) Field CAndIf FieldD is empty  
Or  
IF FieldA is after(further) Field DThen put value from fieldA into "Final Date"


author: Trudy Claspill
body: Hello Sofia,

I have unclicked the Accept Answer button on your behalf because I haven't actually provided an answer for you yet. :-)

I'm going to have to spend a bit of time thinking about this one.


author: Sofia Grunspan
body: Do you want to ignore the empty fields? yes

What if one of the fields gets changed after the automation has run? Do you want this automation to run every time one of the fields is updated? yes

I think if I put Schedule as trigger I can do that.


Tags: cloud

jira-cloud