How to compare a date field to current date using dateCompare()

Steve Beauchamp November 14, 2024

I am trying to build some automation that will update a date field when an action is performed, but only if another date field's value +1w is greater than today's date. I am attempting to accomplish this with scriptrunner's datecompare issuefunction. 

Example:

issuefunction in datecompare("", "Due Date +1w > now()")

However, now() is not accepted as a date value here. Is there a way to call the current date in this context?

2 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 18, 2024

Hi Steve,

Please clarify: What type of Automation are you using to achieve this? Is it ScriptRunner's Custom Script Automation?

If yes, you could try something like the solution provided in the Community Post. It's not 100% exact, but it's a starting point.

Please let me know if you need assistance with the script.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

 

Steve Beauchamp November 26, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

I am using Atlassian's "Automation for Jira" to create the rules. The solution proposed in that post is a lot more complex than I was looking to make this. In the end, I was able to get around this by using smart clauses in the Advanced Compare condition. 

i.e. 

{{issue.customfield_XXXXX}} is greater than {{now.minusBusinessDays(7).format("yyyy-MM-dd")}}

0 votes
K Vivek Rao November 16, 2024

Replace now() with a relative JQL date syntax such as startOfDay() or a specific number of days ago:

issueFunction in dateCompare("", "'Due Date' +1w > startOfDay()")

Here, startOfDay() is a valid JQL function that references the beginning of the current day.

Steve Beauchamp November 26, 2024

I have already tried that and unfortunately, startOfDay() is not accepted as a valid date value in the dateCompare issuefunction either. 

Suggest an answer

Log in or Sign up to answer