How to automatically set due date to the first day of next year.

Mary Kasinger February 10, 2023

Hello,

I am trying to create recurring issues that are using scheduled rules. So these will get created monthly, yearly, quarterly, or weekly depending on a field that I called"monthly", "yearly", "quarterly", or "weekly".

If I'm working on the "Yearly" rule, how do I use automation to assign the due date to be the first day of the following year? I am having trouble with the JSON. So the creation date will be 1/1/2024 and the due date should be 1/1/2024.

This is what I have below.

Recurring Yearly Tasks.png

1 answer

1 vote
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.
February 10, 2023

Hi @Mary Kasinger -- Welcome to the Atlassian Community!

There are built-in date-time functions that could help do that: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/

For example using plusYears() and dayOfYear() you could adjust {{now}} to the first of the next year with:

{{now.plusYears(1).dayOfYear(1)}}

Please consider also examining the time adjustments if that is relevant for your use case.

Kind regards,
Bill

Mary Kasinger February 14, 2023

Hi Bill,

Sorry for the late reply, and thanks for your answer!

I ran this task to test it out, and it failed. Attached is a screenshot with my current automation - do you think there is something incorrectly set up on my end? You'll see I have the smart value entered in the "Advanced branching" condition.

I am trying to schedule this to have a due date on the first of every year, and I want this to be also run on the first of every year. I want to do this for my monthly and weekly reports as well, but I figured if I can get the yearly one set up then I can figure out the other ones.

I so appreciate any help and your help so farYearly Recurring.png

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.
February 14, 2023

Hi!

My understanding was you were trying to set the Due Date for specific time frames, and so...there should not be a need for an advanced branch in the rule.

  • If you want the rule to trigger on that date/timeframe, set the scheduled rule schedule using the selections or a CRON expression, and then create the issue and set the Due Date.  As {{now}} will match your date, setting the field is straightforward.
  • If instead want to run the rule at any timeframe, and then create the issues and set the date for the desired value using a smart value expression.  Please look at the example expression I provided for the first of the year.

So the question is: when/under what conditions do you want to create these issues and set the Due Date?

Mary Kasinger February 28, 2023

Thanks, Bill! I was able to create and run the automation to set up the correct due date. I'm now having trouble with duplication of these issues (see below screenshot of scheduled issue followed by the setup behind the action).Jira Automation.png

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.
February 28, 2023

Hi, Mary.

Would you please explain which issues are being duplicated?

And, please post an image of the audit log, expanding the details to show for the different rule runs which you believe are causing duplication.  Thanks!

Mary Kasinger February 28, 2023

HI Bill,

 

Yes, I have a JQL in the scheduled section of the automation rule that is scheduling a weekly run every Monday for every issue in the search that has a frequency = "weekly" (see below screenshot of the first part of the automation I didn't include previously). I hope this is what you need, if not let me know! Thanks so much.

 

Jira Scheduled Automation.png

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.
February 28, 2023

Thanks, and that helps.

The JQL for that trigger will return *all issues* which have frequency = Weekly.  As you are running this rule once a week, the number of issues it finds will increase by one each week.

I am guessing you only want to copy the fields from one, example issue instead.  Does that sound correct?  If so, you could change your rule to only use the most recent issue as a template, like this:

  • trigger: scheduled weekly, without any JQL
  • action: lookup issues to gather your template issues with JQL, such as below, substituting in your project name:
project = myProjectName AND frequency = Weekly ORDER BY Key DESC
  • action: create issue, copying fields from the most recent one.  To do this, set the fields from one of the looked up issues, like this to set the Summary.
{{lookupIssues.first.summary}}

And use that same pattern to set the other fields.

Mary Kasinger February 28, 2023

Hi Bill,

You are correct in what I want to do, which is copy the fields from one existing issue instead. I'm glad my screenshot helped.

  • Trigger: Understood!
  • Action: lookup issues with JQL - I'm not sure what action allows me to use JQL, but I am understanding what your JQL example is doing
  • Action: create issue - I'm using the built in steps to copy the fields, will this result in duplication again, or do I need to use the JSON you've provided? If so, I am not sure what the Summary is in this case.

I so appreciate you being patient with me. Thanks again.

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.
February 28, 2023

The Lookup Issues action accepts your JQL and then returns a set of issues, like this:

Capture2.PNG

You may then access the fields of the returned issues to create your new issue, as shown below.  I recommend specifically selecting your project and issue type using this approach.

Capture3.PNG

The complete rule would look like the one below, including an Advanced Compare Condition to handle the case of no existing issues found.

Capture4.PNG

Like Mary Kasinger likes this
Mary Kasinger March 28, 2023

Hi Bill,

Thanks for the detailed response. I am able to grasp and setup these steps based on your screenshot, but I am still not grasping the "create issue" portion. Do I need to define any the fields in my current issues further? here is my screenshot of what I have set up now.recurring automation rule.png

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 28, 2023

Smart values are name, spacing, and case-sensitive...including the built-in ones.

And I noticed you have the case incorrect for the lookup ones, which would return empty values.  Please try following this template, noting that lookup is lowercase and Issues is uppercase:

{{lookupIssues.first.summary}}
Like Mary Kasinger likes this
Mary Kasinger March 28, 2023

Good to know, thank you. I've updated the smart value case.

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 28, 2023

After the change, did the issue create work as you expected?

Mary Kasinger March 28, 2023

I clicked on "run rule" about 20 minutes ago, still nothing. I will let you know.

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 28, 2023

That should run it immediately...unless the trigger has JQL (which I believe you removed).

What does the audit log show now?

Mary Kasinger March 28, 2023

Ah, I will look at this log moving forward. I am getting some errors (see below). Not sure what the error "project or issue type not set", but no new issues have been created. I did run it just now, apparently it didn't run the first time. Still no new issues.

 

recurringauditlog.png

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 28, 2023

Yup...there are no issues from the trigger...from which to copy the project or type.

In your issue create, if you select the project and issue type from the dropdowns the error will be fixed.

Mary Kasinger March 29, 2023

Oh, I see.  Now, I chose the project and issue type from the dropdowns and ran the rule with some errors. It cannot find the assignee. I tried 3 different ones - copy from issue, parent, and trigger issue.recurringauditlogerror.png

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 29, 2023

Progress!  Okay, for the assignee you can use the same technique with lookup issues, if you want the same person assigned:

{{lookupIssues.first.assignee.accountId}}

If instead you want someone specific, or to use round-robin, etc., you can do this:

  • ...some rule steps
  • action: create issue
  • branch: to most recently created issue
    • action: assign, with all of the possible assignment options
Mary Kasinger March 29, 2023

It was a success in the audit log, but it only created one of the weekly issues instead of the other ones in the lookup array (if that makes sense) see below screenshot. And thank you!recurringauditloglookup.png

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 29, 2023

Mary, I think I missed something from the beginning of your scenario...I thought you were adding a single weekly issue, for each week. 

Do you instead want to add several different issues, which re-occur for each week?

Mary Kasinger March 29, 2023

Hi Bill, perhaps I am the one who misunderstood. Yes, I do want to create and add an issue for every issue that has frequency = "weekly", and re-occur each week. I also have monthly and yearly issues that I will use the same automation setup for. The original scenario was working but duplicated the issue creation because every week more would be added, so it was copying every single issue existing. I would want the original to be copied, or the most recently created issue with frequency = "weekly" to be added on a recurring basis each week.

 

Sorry about the confusion.

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 29, 2023

A key question is: do the weekly issues finish during each week?

If so, you can probably use a JQL statement to find the issues, iterate over them with either a scheduled trigger or branch on JQL, and create (or clone) to new issues.

If they do not finish during each week, you will need a way to create the set of issues, regardless of any existing "weekly" issues...

  • The simplest way to do that is to create some template issues which remain in the backlog, which are copied each week with the rule.  Although this would not meet your idea to copy from the most recent week's issues.
  • A more complicated way is to identify the week information with the set for copying.  For example, use {{now}} and subtract 7 days, find the last issues by their created date and other JQL criteria, and copy those issues:

project = myProjectName and frequency = Weekly AND created >= {{now.toStartOfDay.minusDays(7)

I suggest trying that JQL with advanced issue search to see manually to see if it works for you.  When used stand-alone, you would need to enter the date/time manually.

Suggest an answer

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

Atlassian Community Events