Advanced Automation: date comparison with now.StartOfMonth behaves unexpectedly

Casey Gould March 20, 2023

We have a custom date field that shouldn't be earlier than the first of the current month under some conditions.

Ex: This is March, so it shouldn't be set any earlier than March 1. Anytime in March or later is fine.

I have an automation set up already that works most of the time, but the behavior for a certain case is unexpected.

Automation structure: WHEN (specific field) changes AND (specific field) now = (result) AND (date comparison = true) THEN add a comment to the issue printing those dates.

The date comparison is this, using the "Advanced Compare condition"
{{issue.Custom Date}}

is less than

{{now.startOfMonth}}

 

Testing examples for custom date produces the following:

  • last month
    expectation: conditional triggered, automation comments
    actual: as expected
  • next month
    expectation: condition not triggered, no comment
    actual: as expected
  • earlier this month
    expectation: condition not triggered, no comment
    actual: as expected
  • later this month
    expectation: condition not triggered, no comment
    actual: comment!

Testing it just now (March 20) with a Custom Date = March 23, my comment printed out as "Custom Date field cannot be any earlier than the first day of this month when [internal conditions] (March 1, 2023). The field is currently set to March 23, 2023."

Obviously the comment doesn't make sense (March 23 isn't earlier than March 1), but I'm not sure what the nuance is with now.startOfMonth that it would behave like this.

Documentation:
https://confluence.atlassian.com/automation/jira-smart-values-date-and-time-993924864.html
https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/

Thoughts?

Summary: Checking if a custom date is less than now.startOfMonth works as expected unless the custom date is between now and the end of this month.

1 answer

1 accepted

1 vote
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2023

Hi @Casey Gould 

Is your custom field a date field or a date/time field?

If it is a date field, what I suspect is happening is the values are not comparing as you expect because one (or both) are converting to text for comparison).  You could force the behavior you want by either:

  • using the date diff function and checking the result is what you expect (positive or negative)
  • using the date formatting features to force comparable values, such as with {{now.startOfMonth.jiraDate}} and {{issue.customDateField.jiraDate}}

Kind regards,
Bill

Casey Gould March 20, 2023

Of course - date formatting!

Thanks, the .jiraDate seems to have done the trick!

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events