How to select the least date amongst the list of dates selected in a multi-select field?

Aman Jain
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 1, 2024

I have a multi-select custom field with several dates as option. I want to select the least date amongst the selected options and put it in a different custom date field.

1 answer

0 votes
Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2024

Hey @Aman Jain 

This is a good question! One that's quite challenging to work through, but I believe you could achieve this with automation. I've not tested this specific solution, but let me know how you go.

Right - let's jump in!

  1. TRIGGER: Field value changed
    1. Field to monitor: Your custom field
    2. Change type: All changes
    3. For: all issue operations
  2. Add component: THEN: Add an action: Create variable
    1. Variable name: smallestDate
    2. Smart value: 2099-01-01
      1. By setting it so far in the future all dates you offer will be less than this
  3. FOR EACH: Add a branch: Advanced branching
    1. Smart value: {{issue.custom field name}}
    2. Variable name: {{currentDate}}
    3. Add to branch: IF: Add a condition: {{smart values}} condition
      1. First value: {{currentDate.jqlDate}}
      2. Condition: less than
      3. Second value: {{smallestDate.jqlDate}}
    4. Add to branch: THEN: Add an action: Create variable
      1. Variable name: smallestDate
      2. Smart value: {{currentDate.jqlDate}}
  4. (Not in the branch now) Add component: IF: Add a condition: {{smart values condition}}
    1. First value: {{smallestDate}}
    2. Condition: does not equal
    3. Second value: 2099-01-01
  5. Add component: THEN: Add an action: Edit issue
    1. Fields: Due date(or whatever date field you are using)
    2. Value: {{smallestDate.jqlDate}}

Let's go over what this does in plain english!

  1. When the customField value changes (at all) we want to check we still have the smallest date
    1. You could change this to be only on creation or on transition etc.
  2. We'll create a dummy variable to be able to compare dates again, by making this be January 1st 2099 all dates will be less than this.
  3. Now, let's compare every date the person has selected and make sure it's the smallest one by comparing it to our current smallest one. If it's smaller, let's update our current smallest one.
  4. Lastly, let's check that the value isn't the default value (e.g. they removed all values), and if we have a valid one, update our issue's Due date (or whatever date field you're using).

Lastly - a screenshot to help!

smallest date.png

Aman Jain
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 1, 2024

Thanks Jovin for the answer. However, when I am running this automation, log shows that the issue did not match the condition.

Please note that the values in the multi-select field are not dates exactly. I am extracting out the dates from the names of the field values.

For an instance, "ABC - 2024-01-12" is the exact value in the multi-select field and I am extracting it using "{{issue.Test Field.value.right(10)}}" where "Test Field" is the custom field name. 

Let me know if I need to do something else.

Here is the screenshot:

Screenshot 2024-07-01 at 6.24.52 PM.png

Screenshot 2024-07-01 at 6.39.11 PM.pngScreenshot 2024-07-01 at 6.39.51 PM.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events